Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python HTTP Error 505: HTTP Version Not Supported

Tags:

python

sql

yql

I have the following code:

import re
from re import sub

import cookielib
from cookielib import CookieJar
import urllib2
from urllib2 import urlopen

cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders=[('user-agent' , 'Safari/7.0.2')]

def check(word):
    try:
        query = "select * from geo.places where text ='"+word+"'"
        sourceCode=opener.open('http://query.yahooapis.com/v1/public/yql?q='+query+'&diagnostics=true').read()
        print sourceCode
    except Exception, e:
        print str(e)
        print 'ERROR IN MAIN TRY'

myStr = ['I','went','to','Boston']
for item in myStr:
        check(item)

I am trying to query select * from geo.places where text = 'Boston' (for example).

I keep receiving this error:

    HTTP Error 505: HTTP Version Not Supported
    ERROR IN MAIN TRY

What can cause this error and how can I solve it?

like image 727
Jeren Avatar asked Dec 14 '25 00:12

Jeren


2 Answers

The URL you construct is not a valid URL. What you send is

GET /v1/public/yql?q=select * from geo.places where text ='I'&diagnostics=true HTTP/1.1
Accept-Encoding: identity
Host: query.yahooapis.com
Connection: close
User-Agent: Safari/7.0.2

There should be no spaces inside the URL, e.g. you have to do proper URL encoding (replace space with '+' etc). I guess requests just fixes the bad URL for you.

like image 159
Steffen Ullrich Avatar answered Dec 15 '25 12:12

Steffen Ullrich


Your query might have blank spaces in between. Requests take care of the white spaces in your url and hence you don't have to take care of it. Just replace each " " by "%20" to make the url work.

like image 38
Swikriti Jain Avatar answered Dec 15 '25 14:12

Swikriti Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!