gpt4 book ai didi

Python HTTP 错误 505 : HTTP Version Not Supported

转载 作者:太空宇宙 更新时间:2023-11-04 06:55:34 24 4
gpt4 key购买 nike

我有以下代码:

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)

我正在尝试查询 select * from geo.places where text = 'Boston'(例如)。

我一直收到这个错误:

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

什么会导致此错误,我该如何解决?

最佳答案

您构造的 URL 不是有效的 URL。你发送的是

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

URL 中不应有空格,例如您必须进行正确的 URL 编码(用“+”等替换空格)。我想 requests 只是为您修复了错误的 URL。

关于Python HTTP 错误 505 : HTTP Version Not Supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23715943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com