FQL multiquery from python fails with unicode query

前端 未结 2 1427
予麋鹿
予麋鹿 2021-01-16 05:55

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 = m         


        
2条回答
  •  星月不相逢
    2021-01-16 06:20

    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

提交回复
热议问题