python HTTP错误302

2024-04-26 18:49:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直得到一个HTML302错误,但我很确定错误来了 从这里的一些代码中我不知道具体在哪里以及如何修复它。在

headers ={'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3','Accept-Encoding': 'gzip, deflate, sdch','Accept-Language': 'en-US,en;q=0.8','Connection': 'keep-alive'}

req_obj = urllib.request.Request(url, method=method,headers=headers)

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
response = opener.open(req_obj)
json_resp = json.loads(response.read().decode('utf-8'))

我得到的错误是

^{pr2}$

提前谢谢


Tags: jsonobjapplicationresponse错误xmlopenerurllib2
1条回答
网友
1楼 · 发布于 2024-04-26 18:49:21

这是您试图访问的服务器的问题。头的Location参数与您尝试访问的URL相同,这将导致无限循环。在

例如,如果我要去http://example.com/foo,并且它告诉我资源已被移动到http://example.com/foo,那么我将根据请求转到{}。但是,这将告诉我http://example.com/foo已被移动到http://example.com/foo。以此类推。在

相关问题 更多 >