使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)报错. 原因:编码未进行转换. 解决方式:print时,在后面加上encode("utf-8")即可. 例如: tx = driver.find_element_by_xpath(".//*[@id='1']/…
在window平台,文件的默认编码是gbk, 此时如果写入的字符串的编码是utf-8就会引发这种错误,打开文件的编码必须与字符串的编码一致 with open('content.txt','w',encoding='utf-8') as f: r.write() 这样就不会报错 原创链接:https://blog.csdn.net/life_is_too_hard/article/details/78384562…
这个问题很奇怪,在服务器上执行一个写数据库的python文件,正常执行,但是使用java的ssh进行调用脚本,发现就是不执行数据库的写入,然后使用了try except的方式,打印了错误信息,发现报错: 'ascii' codec can't encode characters in position 0-15: ordinal not in range(128) 解决方案: 在python文件中加入以下3句话 import sys reload(sys) sys.setdefaultencod…
Xcode升级10.3后XiB文件包错,提示: Failed to find or create execution context for description '<IBCocoaTouchPlatformToolDescription: 0x7fefbefd1d80> System content for IBCocoaTouchFramework-EightAndLater <IBScaleFactorDeviceTypeDescription: 0x7fefbebf4f70&g…
执行下面代码报错: UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal byte sequence import time print(time.strftime("%Y年%m月%d日 %H时%M分%S秒",time.localtime())) 报错原因为有中文字符,修改为下面代码即可 import time print(time.strftime('%Y{y…
背景 在做接口自动化的时候,Excel作为数据驱动,里面存了中文,通过第三方库读取中文当请求参数传入 requests.post() 里面,就会报错 UnicodeEncodeError: 'latin-1' codec can't encode characters in position 13-14: Body ('小明') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF…