HTTP错误:HTTP错误400:错误请求(必须使用urllib2发出HTTP请求)

时间:2017-05-10 18:24:39

标签: python-2.7 http google-app-engine urllib2

我正面临一个错误,所有在这里建立的类似答案对我没有帮助。

我得到了

  

HTTPError:HTTP错误400:错误请求

当我尝试执行Delete.py文件的下一行代码

def DeleteFBUser(idSocial):
    url = 'https://graph.facebook.com/{}/permissions&access_token={}'
    url = url.format(idSocial, FBToken)
    req = urllib2.Request(url)
    req.get_method = lambda: 'DELETE'
    response = urllib2.urlopen(req)

这是完整的追踪

Traceback (most recent call last):
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/apps/e~gold-circlet-160109/20170510t200435.401160541821948379/Delete.py", line 12, in dispatch
webapp2.RequestHandler.dispatch(self)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/e~gold-circlet-160109/20170510t200435.401160541821948379/Delete.py", line 27, in get
FBLogin.DeleteFBUser(idSocial=self.session["ECommerceUser"]["idSocial"])
File "/base/data/home/apps/e~gold-circlet-160109/20170510t200435.401160541821948379/FBLogin.py", line 46, in DeleteFBUser
response = urllib2.urlopen(req)
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/urllib2.py", line 158, in urlopen
return opener.open(url, data, timeout)
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/urllib2.py", line 439, in open
response = meth(req, response)
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/urllib2.py", line 552, in http_response
'http', request, response, code, msg, hdrs)
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/urllib2.py", line 477, in error
return self._call_chain(*args)
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/urllib2.py", line 411, in _call_chain
result = func(*args)
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/urllib2.py", line 560, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您是否尝试过:graph.facebook.com/me?access_token=TOKEN&fields=id,name,email

而不是:graph.facebook.com/{}/permissions&access_token={}

因为这是对facebook api的正确调用。