Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "Maintype was not text, image, or querystring" exception. #281

Open
scottydelta opened this issue Apr 20, 2016 · 8 comments
Open
Assignees
Milestone

Comments

@scottydelta
Copy link

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]:
@martey
Copy link
Member

martey commented Apr 20, 2016

Are you using 1.0.0? What version were you using when the code was working?

@scottydelta
Copy link
Author

scottydelta commented Apr 20, 2016

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

@martey
Copy link
Member

martey commented Apr 20, 2016

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 martey changed the title Getting error on get_connections Remove "Maintype was not text, image, or querystring" exception. Apr 20, 2016
@martey martey added this to the v2.0.0 milestone Apr 20, 2016
@scottydelta
Copy link
Author

@martey is there any quick fix for this?

@scottydelta
Copy link
Author

Worked when making limit to 25. earlier I used to get reduce amount of data error and making it earlier 80 worked.

@martey
Copy link
Member

martey commented Apr 21, 2016

@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.

@ghost
Copy link

ghost commented Feb 18, 2017

What is left to do in this PR?

@martey martey modified the milestones: v3.0.0, v4.0.0 Jul 19, 2018
@martey martey modified the milestones: v4.0.0, v5.0.0 Jul 28, 2020
@MuffinFox
Copy link

MuffinFox commented Nov 10, 2020

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants