urllib2.HTTPError:HTTP错误404:未找到 [英] urllib2.HTTPError: HTTP Error 404: Not Found

查看:2128
本文介绍了urllib2.HTTPError:HTTP错误404:未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用树莓派运行我的Python脚本时出现错误信息

$ c> Traceback(最近一次调用最后一次):> Traceback(最近一次调用最后一次):
在(模块)中的第6行文件test.py
import appengineauth
File /home/pi/Downloads/google_appengine/appengineauth.py,第30行,在(模块)中
auth_resp = urllib2.urlopen(auth_req)
文件/usr/lib/python2.7/urllib2 .py,第154行,在urlopen
返回opener.open(url,data,timeout)
文件/usr/lib/python2.7/urllib2.py,第437行,打开
response = meth(req,response)
在http_response
'http'中的文件/usr/lib/python2.7/urllib2.py,第550行,请求,响应,代码, msg,hdrs)
文件/usr/lib/python2.7/urllib2.py,第475行,错误
返回self._call_chain(* args)
文件/ usr / lib / python2.7 / urllib2.py,第409行,在_call_chain
result = func(* args)
文件/usr/lib/python2.7/urllib2.py第558行,在http_error_default
中引发HTTPError(req.get_full_url(),code,msg,hdrs,fp)
urllib2.HTTPError:HTTP错误404:未找到

我可以访问该网站。如果您使用 https://github.com/adafruit/Tweet-a-Watt/blob/ master / appengineauth.py (你不会告诉我们你从哪里得到 appengineauth.py ,从而迫使我们猜测),并且它的行



  auth_uri ='https://www.google.com/accounts/ClientLogin'

那么您可能会遇到 https://developers.google.com/identity/protocols/AuthForInstalledApps ,我引用:


<重要提示:ClientLogin自2012年4月20日起正式被弃用,现在不再可用。对ClientLogin的请求将失败,并返回HTTP 404响应。我们建议您尽快迁移到OAuth 2.0。


即,您所得到的404将完全是症状警告会告诉您,现在ClientLogin已被移除,超过原始弃用警告后的3.5年。



不确定如何最好地将Raspberry Pi连接到App Engine (或任何其他需要验证的Google服务)与OAuth 2.0(因为ClientLogin不再是一个选项)。 http://guy.carpenter。 id.au/gaugette/2012/11/06/using-google-oauth2-for-devices/ (在弃用之后不久写入,但巧妙地避免依赖已经弃用的ClientLogin服务)建议使用OAuth2 for Devices 库并总结如何使用它;我自己并没有尝试过这个库(我没有Raspberry Pi来尝试它),但它看起来像是一个潜在的富有成果的途径,供您探索。


My Error Message when running my python scripts using a raspberry pi

Traceback (most recent call last):>Traceback (most recent call last):
  File "test.py", line 6, in (module)
    import appengineauth
  File "/home/pi/Downloads/google_appengine/appengineauth.py", line 30, in (module)
    auth_resp = urllib2.urlopen(auth_req)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

I'm able to access the website. Not too sure what is the actual problem.

解决方案

If you're using https://github.com/adafruit/Tweet-a-Watt/blob/master/appengineauth.py (you don't tell us where you got your appengineauth.py from, thus forcing us to guess), and its line

auth_uri = 'https://www.google.com/accounts/ClientLogin'

then you're likely running into the deprecation documented at https://developers.google.com/identity/protocols/AuthForInstalledApps , and I quote:

Important: ClientLogin has been officially deprecated since April 20, 2012 and is now no longer available. Requests to ClientLogin will fail with a HTTP 404 response. We encourage you to migrate to OAuth 2.0 as soon as possible.

I.e, the 404 you're getting would then be exactly the symptom the warning tells you about, now that ClientLogin has been removed, more than 3.5 years after the original deprecation warning.

Not sure how best to connect your Raspberry Pi to App Engine (or any other Google service requiring authentication) with OAuth 2.0 (since ClientLogin is not an option any more). http://guy.carpenter.id.au/gaugette/2012/11/06/using-google-oauth2-for-devices/ (written shortly after the deprecation but smartly avoiding reliance on the already-deprecated ClientLogin service) recommends an "OAuth2 for Devices" library and summarizes how to use it; I haven't tried that library myself (and I don't have a Raspberry Pi to try it on) but it does seem like a potentially fruitful avenue for you to explore.

这篇关于urllib2.HTTPError:HTTP错误404:未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆