Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Если type(url) == unicode и в data есть байты со значениями больше 0x7F(128-255), urllib2 пытается декодировать данные в какую-то, только ему известную кодировку
- >>> req = urllib2.Request(unicode('http://site.ru/test'), data='\xff'); urllib2.urlopen(req)
- Traceback (most recent call last):
- File "<pyshell#55>", line 1, in <module>
- req = urllib2.Request(unicode('http://site.ru/test'), data='\xff'); urllib2.urlopen(req)
- File "C:\Python27\lib\urllib2.py", line 127, in urlopen
- return _opener.open(url, data, timeout)
- File "C:\Python27\lib\urllib2.py", line 404, in open
- response = self._open(req, data)
- File "C:\Python27\lib\urllib2.py", line 422, in _open
- '_open', req)
- File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
- result = func(*args)
- File "C:\Python27\lib\urllib2.py", line 1214, in http_open
- return self.do_open(httplib.HTTPConnection, req)
- File "C:\Python27\lib\urllib2.py", line 1181, in do_open
- h.request(req.get_method(), req.get_selector(), req.data, headers)
- File "C:\Python27\lib\httplib.py", line 973, in request
- self._send_request(method, url, body, headers)
- File "C:\Python27\lib\httplib.py", line 1007, in _send_request
- self.endheaders(body)
- File "C:\Python27\lib\httplib.py", line 969, in endheaders
- self._send_output(message_body)
- File "C:\Python27\lib\httplib.py", line 827, in _send_output
- msg += message_body
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
- >>> req = urllib2.Request('http://site.ru/test', data='\xff'); urllib2.urlopen(req)
- Traceback (most recent call last):
- File "<pyshell#56>", line 1, in <module>
- req = urllib2.Request('http://site.ru/test', data='\xff'); urllib2.urlopen(req)
- File "C:\Python27\lib\urllib2.py", line 127, in urlopen
- return _opener.open(url, data, timeout)
- File "C:\Python27\lib\urllib2.py", line 410, in open
- response = meth(req, response)
- File "C:\Python27\lib\urllib2.py", line 523, in http_response
- 'http', request, response, code, msg, hdrs)
- File "C:\Python27\lib\urllib2.py", line 448, in error
- return self._call_chain(*args)
- File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
- result = func(*args)
- File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
- raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
- HTTPError: HTTP Error 404: Not Found
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement