FQL multiquery from python fails with unicode query

邮差的信 提交于 2019-12-01 12:27:26

It's based on how the facebook.py libraries handles the queries. Queries to Facebook all end up needing to be URL encoded.

So, digging through the facebook.py source

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

ends up as

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

Which matches properly as

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

where as

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

ends up as

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

Notice that no handling of u for the unicode part was done before sending to urlencode in the facebook.py library.

https://api.facebook.com, returns no response to this but if you did the same at the graph.facebook.com endpoint you will notice

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

Basically, it chokes on your query.

Try dealing with your Unicode before sending off for Url Encoding

Maybe the problem is that you are mixing and matching the ASCII string on the left parameter with 'example', and using unicode on the right for the query string. Try this:

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

Try it the other way like this:

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

I've known to show respect for the wild wooly world of unicode, maybe you are not encoding your ascii string correctly? Maybe try assembling your unicode string character by character with the unichr(...) command.

If fiddling around with these doesn't fix the problem, then the conclusion is that the fql function pukes when passed unicode. The work around is to always use ASCII strings.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!