Getting 505 HTTP Error in python django

1.9k Views Asked by At

I'm trying to access an api by using urllib2 package. When I run my code, getting an error showing as HTTP Error 505: HTTP Version Not Supported. What should I do? I'm adding the essential parts of my error here. Please help me.Thank you.

This is my error

 HTTPError at /polls/time/page=4010102930/
 HTTP Error 505: HTTP Version Not Supported
 Request Method:    GET
 Request URL:   http://127.0.0.1:8000/polls/time/page%3D4010102930/
 Django Version:    1.9.2
 Exception Type:    HTTPError
 Exception Value:   
 HTTP Error 505: HTTP Version Not Supported
 Exception Location:    C:\Python27\Lib\urllib2.py in http_error_default, line 558
 Python Executable: C:\Users\JpG\Virtual_Env\Scripts\python.exe
 Python Version:    2.7.10
 Python Path:   
 ['E:\\JpGxx\\Python PgMz\\Pure_Python\\DJ_1',
  'E:\\JpGxx\\Python PgMz\\Pure_Python\\DJ_1',
  'C:\\Windows\\SYSTEM32\\python27.zip',
  'C:\\Users\\JpG\\Virtual_Env\\DLLs',
  'C:\\Users\\JpG\\Virtual_Env\\lib',
  'C:\\Users\\JpG\\Virtual_Env\\lib\\plat-win',
  'C:\\Users\\JpG\\Virtual_Env\\lib\\lib-tk',
  'C:\\Users\\JpG\\Virtual_Env\\Scripts',
  'C:\\Python27\\Lib',
  'C:\\Python27\\DLLs',
  'C:\\Python27\\Lib\\lib-tk',
  'C:\\Users\\JpG\\Virtual_Env',
  'C:\\Users\\JpG\\Virtual_Env\\lib\\site-packages',
  'C:\\Python27',
  'C:\\Python27\\lib\\site-packages']
 Server time:   Mon, 28 Mar 2016 22:16:10 +0530
1

There are 1 best solutions below

2
levi On

That error is due to the server that u are trying to access does not support your request HTTP versión, so you need to change it. May be, you need to send 1.0 HTTP request.

import urllib2, httplib
httplib.HTTPConnection._http_vsn = 10
httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0'
print urllib2.urlopen('your_url').read()

I highly recommend to use requests library to handle http requests from python.