Advertisement
stuppid_bot

Python 2.7.5 bug

Jul 9th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. Если type(url) == unicode и в data есть байты со значениями больше 0x7F(128-255), urllib2 пытается декодировать данные в какую-то, только ему известную кодировку
  2.  
  3. >>> req = urllib2.Request(unicode('http://site.ru/test'), data='\xff'); urllib2.urlopen(req)
  4.  
  5. Traceback (most recent call last):
  6.   File "<pyshell#55>", line 1, in <module>
  7.     req = urllib2.Request(unicode('http://site.ru/test'), data='\xff'); urllib2.urlopen(req)
  8.   File "C:\Python27\lib\urllib2.py", line 127, in urlopen
  9.     return _opener.open(url, data, timeout)
  10.   File "C:\Python27\lib\urllib2.py", line 404, in open
  11.     response = self._open(req, data)
  12.   File "C:\Python27\lib\urllib2.py", line 422, in _open
  13.     '_open', req)
  14.   File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
  15.     result = func(*args)
  16.   File "C:\Python27\lib\urllib2.py", line 1214, in http_open
  17.     return self.do_open(httplib.HTTPConnection, req)
  18.   File "C:\Python27\lib\urllib2.py", line 1181, in do_open
  19.     h.request(req.get_method(), req.get_selector(), req.data, headers)
  20.   File "C:\Python27\lib\httplib.py", line 973, in request
  21.     self._send_request(method, url, body, headers)
  22.   File "C:\Python27\lib\httplib.py", line 1007, in _send_request
  23.     self.endheaders(body)
  24.   File "C:\Python27\lib\httplib.py", line 969, in endheaders
  25.     self._send_output(message_body)
  26.   File "C:\Python27\lib\httplib.py", line 827, in _send_output
  27.     msg += message_body
  28. UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
  29. >>> req = urllib2.Request('http://site.ru/test', data='\xff'); urllib2.urlopen(req)
  30.  
  31. Traceback (most recent call last):
  32.  File "<pyshell#56>", line 1, in <module>
  33.    req = urllib2.Request('http://site.ru/test', data='\xff'); urllib2.urlopen(req)
  34.  File "C:\Python27\lib\urllib2.py", line 127, in urlopen
  35.    return _opener.open(url, data, timeout)
  36.  File "C:\Python27\lib\urllib2.py", line 410, in open
  37.    response = meth(req, response)
  38.  File "C:\Python27\lib\urllib2.py", line 523, in http_response
  39.    'http', request, response, code, msg, hdrs)
  40.  File "C:\Python27\lib\urllib2.py", line 448, in error
  41.    return self._call_chain(*args)
  42.  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
  43.    result = func(*args)
  44.  File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
  45.    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
  46. HTTPError: HTTP Error 404: Not Found
  47. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement