Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Urllib2.HTTP错误:HTTP错误400:错误请求_Python_Facebook_Urllib2_Urllib - Fatal编程技术网

Python Urllib2.HTTP错误:HTTP错误400:错误请求

Python Urllib2.HTTP错误:HTTP错误400:错误请求,python,facebook,urllib2,urllib,Python,Facebook,Urllib2,Urllib,我有一段调用facebook API的代码,如下所示: ID = str(cell.value) #ID comes from an excel spread sheet data = json.load(urllib2.urlopen('http://graph.facebook.com/' + urllib.quote(ID) +'/comments?summary=true&limit=0')) Comments_count = int(data.get("summary").ge

我有一段调用facebook API的代码,如下所示:

ID = str(cell.value) #ID comes from an excel spread sheet
data = json.load(urllib2.urlopen('http://graph.facebook.com/' + urllib.quote(ID) +'/comments?summary=true&limit=0'))
Comments_count = int(data.get("summary").get("total_count"))
但是,我在某些URL上遇到错误

Traceback (most recent call last):
  File "FBS.py", line 50, in <module>
    data = json.load(urllib2.urlopen('http://graph.facebook.com/' + urllib.quote(ID) +'/comments?summary=true&limit=0'))
  File "C:\Python27\lib\urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 410, in open
    response = meth(req, response)
  File "C:\Python27\lib\urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python27\lib\urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
回溯(最近一次呼叫最后一次):
文件“FBS.py”,第50行,在
data=json.load(urllib2.urlopen)http://graph.facebook.com/“+urllib.quote(ID)+”/comments?summary=true&limit=0'))
文件“C:\Python27\lib\urllib2.py”,第127行,在urlopen中
return\u opener.open(url、数据、超时)
文件“C:\Python27\lib\urllib2.py”,第410行,打开
响应=方法(请求,响应)
文件“C:\Python27\lib\urllib2.py”,第523行,在http\u响应中
“http”、请求、响应、代码、消息、hdrs)
文件“C:\Python27\lib\urllib2.py”第448行出错
返回自我。调用链(*args)
文件“C:\Python27\lib\urllib2.py”,第382行,在调用链中
结果=func(*args)
文件“C:\Python27\lib\urllib2.py”,第531行,默认为http\u error\u
raise HTTPError(请求获取完整url(),代码,消息,hdrs,fp)
urllib2.HTTPError:HTTP错误400:错误请求
我已经尝试过使用Urllib.quote(ID),但仍然存在同样的问题

非常感谢您的帮助


谢谢

您需要将访问令牌传递给graph api以获取此信息。我建议您使用sdk访问graph api

上的URL是什么?这些身份证是什么?为什么你认为需要引用这个值呢?这些ID是facebook ID。例如,450170755110703,我之所以使用urllib.quote,是因为我从另一个线程中读到它,说它解决了一些人的问题。