版本 Python 3.6
报错:
'ascii' codec can't encode characters in position 8-50: ordinal not in range(128)
究其原因就是中文符号的编码问题
解决:
import pandas as pd
import urllib.parse
path = 'https:xxx.com/(牛牛).xls'
# safe 为无需转码的字符
url = urllib.parse.quote(path,safe=":/=?#")
dates = pd.read_excel(url,keep_default_na=False).to_dict(orient='records')
print(dates)
在Python3.6中遇到'ascii' codec无法编码位置8-50的字符,原因是中文符号编码问题。解决方案是使用urllib.parse.quote函数,通过设置safe参数来处理URL中的特殊字符,例如将中文路径转换为可读URL。然后使用pandas读取Excel文件并将其转换为字典记录,以便进一步处理。

7494

被折叠的 条评论
为什么被折叠?



