我从web服务获取明文到对象p
,我希望使用Python将其存储在.txt
文件中。
我做的事情如下:
with open("output","w") as t2:
t2.write(p.content)
但出现以下编码问题:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 10: ordinal not in range(128)
我在Ubuntu和PycharmIDE上。我怎样才能克服这个问题?
答案 0 :(得分:3)
您可以尝试使用
<?php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile); /
}
?>
或
p2.content.encode('utf-8')