Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

facebook-graph sdk cannot handle unicode character

Can facebook-python sdk handle when posting a japanese message. I can post english message without any problem, but when I try to post japanese

graph.put_object("me", "feed", message=u'あなたが大好きだよ')

i got error below. What should I do?

Traceback (most recent call last):

File "/base/data/home/apps/s~posttofacebook123456/1.365133296513228525/kay/app.py", line 371, in get_response
response = view_func(request, **values)

File "/base/data/home/apps/s~posttofacebook123456/1.365133296513228525/myapp/views.py", line 116, in index
graph.put_object("me", "feed", message=u'あなたが大好きだよ')

File "/base/data/home/apps/s~posttofacebook123456/1.365133296513228525/myapp/facebook.py", line 140, in put_object
post_args=data)

File "/base/data/home/apps/s~posttofacebook123456/1.365133296513228525/myapp/facebook.py", line 291, in request
post_data = None if post_args is None else urllib.urlencode(post_args)

File "/python27_runtime/python27_dist/lib/python2.7/urllib.py", line 1289, in urlencode
v = quote_plus(str(v))

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-8: ordinal not in range(128)
like image 897
John Avatar asked Jul 05 '26 17:07

John


1 Answers

You need to post it as UTF8.

graph.put_object("me", "feed", message='あなたが大好きだよ'.encode('utf-8'))

like image 154
Shay Erlichmen Avatar answered Jul 07 '26 05:07

Shay Erlichmen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!