Python非数字端口异常
我尝试使用带有urllib2的json正文发送post请求:Python非数字端口异常,python,http,urllib2,Python,Http,Urllib2,我尝试使用带有urllib2的json正文发送post请求: request = urllib2.Request('http://localhost:8090/api/', jdata, {'Content-Type': 'application/json'}) f = urllib2.urlopen(request) 但有一个例外: File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen return _opener.
request = urllib2.Request('http://localhost:8090/api/', jdata, {'Content-Type': 'application/json'})
f = urllib2.urlopen(request)
但有一个例外:
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 407, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 439, in error
result = self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 626, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/lib/python2.7/urllib2.py", line 401, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 419, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1211, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1150, in do_open
h = http_class(host, timeout=req.timeout) # will parse host:port
File "/usr/lib/python2.7/httplib.py", line 693, in __init__
self._set_hostport(host, port)
File "/usr/lib/python2.7/httplib.py", line 721, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '8090��>��hbWb�ba'
我怎样才能修好它
谢谢。似乎urllib2函数没有正确解析您的请求。你为什么不试试卷发呢
import pycurl
c = pycurl.Curl()
c.setopt(c.URL, 'http://myfavpizzaplace.com/order')
c.setopt(c.POSTFIELDS, 'pizza=Quattro+Stagioni&extra=cheese')
c.setopt(c.VERBOSE, True)
c.perform()
来自的示例应按原样工作。如果在源文件中使用非ascii字符编码;确保url仅包含ascii字符,例如,不要使用Unicode斜杠,例如∕ 错误地