File unicode(utf8)将(阿拉伯语、希伯来语、中文)写入云存储中的文件,Python

File unicode(utf8)将(阿拉伯语、希伯来语、中文)写入云存储中的文件,Python,file,google-app-engine,python-2.7,utf-8,google-cloud-storage,File,Google App Engine,Python 2.7,Utf 8,Google Cloud Storage,我想用多种语言写入文件,然后将其存储在云存储中。这是我的代码: file=gcs.open(filename,'w',content_type='text/html; charset=utf-8') file.write(str(content)) file.close() 我如何修改它? 谢谢看起来这可能是在调用file.write之前将字符串编码为UTF-8的问题。那么: file.write(content.encode('utf-8')) 如果内容具有utf

我想用多种语言写入文件,然后将其存储在云存储中。这是我的代码:

file=gcs.open(filename,'w',content_type='text/html; charset=utf-8')

      file.write(str(content))
      file.close()
我如何修改它?
谢谢

看起来这可能是在调用
file.write之前将字符串编码为UTF-8的问题。那么:

file.write(content.encode('utf-8'))

如果内容具有utf-8,请使用content.encode('utf-8')将其转换为二进制。更多信息:非常感谢。现在它正在工作:)