【发布时间】:2016-08-25 15:29:58
【问题描述】:
我正在用 Python 将一些 Unicode 字符串写入 HTML。我这样做的方式是在内部使用 Unicode,并且只在输出时进行编码。所以像:
with open(filename, 'w') as f:
f.write(s.encode("utf-8"))
这在我的本地机器上可以正常工作。但是当它放到 Travis CI 上时,生成的文件有 ü 代替 ü。有什么想法吗?
这是我的.travis.yml:
language: python
python: 2.7.10
install: pip install -r requirements.txt
script: python main.py -d
deploy:
provider: s3
access_key_id: XXX
secret_access_key:
secure: XXX
bucket: www.my.org
region: us-east-1
skip_cleanup: true
default_text_charset: 'utf-8'
local-dir: output
更新
可以重现该问题的最小 Python 代码如下:
from pyquery import PyQuery as pq
argurl = 'http://hackingdistributed.com/tag/bitcoin/'
d = pq(url=argurl)
authors = []
for elem in d.find("h2.post-title a"):
pubinfo = pq(elem).parent().parent().find(".post-metadata .post-published")
author = pq(pubinfo).find(".post-authors").html().strip()
authors.append(author)
with open('output/test.html', 'w') as f:
f.write(': '.join(authors).encode('utf-8'))
查看output/test.html 以查看ü。
【问题讨论】:
-
能否附上您正在使用的
.travis-ci.yml以及最小的 Python 示例代码? -
@tambre 请查看我的编辑。
-
你在本地使用的是什么 Python 版本?
-
@tambre Python 2.7.10
-
我怀疑这是您的 Python 代码中的一个错误。您介意在 Travis 上发布能够重现此问题的最少量 Python 代码吗?
标签: python unicode travis-ci python-unicode