facebook-sdk
facebook-sdk copied to clipboard
Remove "Maintype was not text, image, or querystring" exception.
I am getting this error but the same code was working perfectly fine in march.
In [14]: posts = graph.get_connections('johnkasich', 'posts', limit=80, fields='likes.su
mmary(true),comments.summary(true),name,message,type,id,created_time,shares')
---------------------------------------------------------------------------
GraphAPIError Traceback (most recent call last)
<ipython-input-14-b26ea9d04ab5> in <module>()
----> 1 posts = graph.get_connections(elem, 'posts', limit=80, fields='likes.sum
mary(true),comments.summary(true),name,message,type,id,created_time,shares')
c:\users\vbajaj2.asurite\desktop\fbapp\env\lib\site-packages\facebook\__init__.p
yc in get_connections(self, id, connection_name, **args)
118 """Fetches the connections for given object."""
119 return self.request(
--> 120 "%s/%s/%s" % (self.version, id, connection_name), args)
121
122 def put_object(self, parent_object, connection_name, **data):
c:\users\vbajaj2.asurite\desktop\fbapp\env\lib\site-packages\facebook\__init__.p
yc in request(self, path, args, post_args, files, method)
269 raise GraphAPIError(response.json())
270 else:
--> 271 raise GraphAPIError('Maintype was not text, image, or querys
tring')
272
273 if result and isinstance(result, dict) and result.get("error"):
GraphAPIError: Maintype was not text, image, or querystring
In [15]:
Are you using 1.0.0? What version were you using when the code was working?
I did a pip upgrade after it dint work today but that dint help. Right now I got 1.0.0 on pip freeze.
Irrespective of that, the same query is working on the Graph API Explorer: https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=johnkasich%2Fposts%3Ffields%3Dlikes.summary(true)%2Ccomments.summary(true)%2Cname%2Cmessage%2Ctype%2Cid%2Ccreated_time%2Cshares&version=v2.6
I ran the get_connections
code and pulled the response from Facebook:
{"error":{"code":1,"message":"Please reduce the amount of data you're asking for, then retry your request"}}
This isn't an issues with get_connections
, but rather with the error handling code in the request
method - the generic "Maintype was not text, image, or querystring" error message hides other exceptions and should be changed.
@martey is there any quick fix for this?
Worked when making limit to 25. earlier I used to get reduce amount of data
error and making it earlier 80 worked.
@martey is there any quick fix for this?
If you are referring to the fact that you might receive a generic error message, you could replace line 271 (that raises the generic error message) with return response
.
What is left to do in this PR?
The error handling of the lib is unfortunately still broken, can we agree on removing the generic error. It seems not to be possible to handle server errors like 50x
I see 2 main issues in the main requests
method:
except requests.HTTPError as e:
response = json.loads(e.read())
raise GraphAPIError(response)
Not sure when HTTPError will be raised because raise_for_status
is not in use, but if i mock Http Errors, this wont work, obviously because AttributeError: 'HTTPError' object has no attribute 'read'
, also HTTPError.response is lost if it was working.
Further we need to get rid of this generic error, response context is lost:
raise GraphAPIError("Maintype was not text, image, or querystring")