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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With