gpt4 book ai didi

python - facebook-graph sdk 无法处理 unicode 字符

转载 作者:太空宇宙 更新时间:2023-11-03 14:29:01 25 4
gpt4 key购买 nike

发布日语消息时,facebook-python sdk 可以处理吗?我可以毫无问题地发布英文消息,但是当我尝试发布日语时

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

我在下面遇到错误。我该怎么办?

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)

最佳答案

您需要将其发布为 UTF8。

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

关于python - facebook-graph sdk 无法处理 unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com