分类目录归档:排错记录

python处理UTF-8文件的BOM头

问题

用requests库下载一个xml文件,结果 return response.content 的时候发现返回的文本是这样的

b'\xef\xbb\xbf<?xxxxxxxxxx

前面有b’\xef\xbb\xbf
写入文件的时候就有问题了
查了一下EF BB BF是被称为 Byte order mark (BOM)的文件标记,用来指出这个文件是UTF-8编码
在Stack Overflow上面搜到一个类似的问题
https://stackoverflow.com/questions/13590749/reading-unicode-file-data-with-bom-chars-in-python

解决方案

>>> b'\xef\xbb\xbfhello'.decode('utf-8-sig')
'hello'

github报错failed to push some refs to ‘git

$ git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
To git@github.com:Tuesdday/pythoncode.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:Tuesdday/pythoncode.git'
#提交代码时报错
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

继续阅读