Python fql instances terminate using unicode query

Using python 2.6.5 and facebook-sdk 0.3.2 this:

import facebook api = facebook.GraphAPI(token) api.fql({'example':u"SELECT uid2 FROM friend WHERE uid1 = me()"}) 

returns an empty list, but this one

 api.fql({'example':"SELECT uid2 FROM friend WHERE uid1 = me()"}) 

works. If any of the queries are unicode strings, the result will be [] error free.

Facebook developer support suggests that I ask about stackoverflow, what is wrong. Their explanation was that, since no one had reported this error, maybe I am doing something wrong. So they closed the bug .

Thoughts on how to deal with it?

+1
source share
2 answers

It is based on how facebook.py libraries handle requests. Requests on Facebook all ultimately need URL encoding.

So breaking through the source facebook.py

 api.fql({'example':"SELECT uid2 FROM friend WHERE uid1 = me()"}) 

ends as

queries%3D%7B%27example%27%3A+%27SELECT+uid2+FROM+friend+WHERE+uid1+%3D+me%28%29%27%7D

Which matches correctly as

 queries={'example': 'SELECT uid2 FROM friend WHERE uid1 = me()'} 

where as

 api.fql({'example':u"SELECT uid2 FROM friend WHERE uid1 = me()"}) 

ends as

queries%3D%7B%27example%27%3A+u%27SELECT+uid2+FROM+friend+WHERE+uid1+%3D+me%28%29%27%7D

Please note that the processing of the u element for the unicode part was not performed before sending to urlencode in facebook.py library.

https://api.facebook.com does not respond to this, but if you did the same on the endpoint of graph.facebook.com, you will notice

(# 601) Analyzer error: unexpected '{' at position 0.

Basically, it pinches your request.

Try to deal with your Unicode before submitting for URL encoding

+2
source

Maybe the problem is that you mix and match the ASCII string on the left of the parameter with the example, and using Unicode on the right for the query string. Try the following:

 api.fql({u'example':u"SELECT uid2 FROM friend WHERE uid1 = me()"}) 

Try it like this:

 api.fql({u'example':"SELECT uid2 FROM friend WHERE uid1 = me()"}) 

I know that I respect the wild wooly Unicode world, maybe you are not coding your ascii string correctly? Perhaps try to compile a Unicode string character with a character using the unichr (...) command.

If you mess around with them, this does not fix the problem, then the conclusion is that the fql function runs when passed in Unicode. Work around is to always use ASCII strings.

Source: http://docs.python.org/howto/unicode.html

0
source

Source: https://habr.com/ru/post/1440325/


All Articles