草庐IT

num_characters

全部标签

python - 统一码编码错误 : 'ascii' codec can't encode character when trying a HTTP POST in Python

我正在尝试使用Unicode字符串(u'\xe4\xf6\xfc')作为Python中的参数执行HTTPPOST,但我收到以下错误:UnicodeEncodeError:'ascii'编解码器无法编码字符这是用于制作HTTPPOST的代码(使用httplib2)http=httplib2.Http()userInfo=[('Name',u'\xe4\xf6\xfc')]data=urlencode(userInfo)resp,content=http.request(url,'POST',body=data)关于如何解决这个问题有什么想法吗? 最佳答案

python - 统一码编码错误 : 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

这个问题在这里已经有了答案:UnicodeerrorOrdinalnotinrange(1个回答)关闭5年前。我只是想解码类似\uXXXX\uXXXX\uXXXX的字符串。但是我得到一个错误:$pythonPython2.7.6(default,Sep92014,15:04:36)[GCC4.2.1CompatibleAppleLLVM6.0(clang-600.0.39)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>printu'\u041e\u043b\u044c\u0433\u0

python - Pandas 数据框 : ValueError: num must be 1 <= num <= 0, 不是 1

我在尝试绘制pandasdataframe时遇到以下错误:ValueError:nummustbe1代码:importmatplotlib.pyplotaspltnames=['buying','maint','doors','persons','lug_boot','safety']custom=pd.DataFrame(x_train)//onlyaportionofthecsvcustom.columns=namescustom.hist()plt.show()我尝试再次从csv读取文件,但我得到了完全相同的错误。编辑:printx_train输出:[[0.00.00.00.00

python : UnicodeEncodeError: 'latin-1' codec can't encode character

我在调用api的情况下,根据api的结果,我为api中的每条记录调用数据库。我的api调用返回字符串,当我对api返回的项目进行数据库调用时,对于某些元素,我收到以下错误。Traceback(mostrecentcalllast):File"TopLevelCategories.py",line267,incursor.execute(categoryQuery,{'title':startCategory});File"/opt/ts/python/2.7/lib/python2.7/site-packages/MySQLdb/cursors.py",line158,inexecut

python - Num day to Name day 与 Pandas

如果我使用这个函数pd.DatetimeIndex(dfTrain['datetime']).weekday我得到了日期,但是我找不到任何给出日期名称的函数...所以我需要将0转换为星期一,将1转换为星期二,依此类推。这是我的数据框的示例:datetimeseasonholidayworkingdayweathertempatemphumiditywindspeedcount02011-01-0100:00:0010019.8414.395810.00001612011-01-0101:00:0010019.0213.635800.00004022011-01-0102:00:0010

python - 将 mkl_set_num_threads 与 numpy 一起使用

我正尝试像这样使用mkl_set_num_threads设置numpy计算的线程数importnumpyimportctypesmkl_rt=ctypes.CDLL('libmkl_rt.so')mkl_rt.mkl_set_num_threads(4)但我一直遇到段错误:ProgramreceivedsignalSIGSEGV,Segmentationfault.0x00002aaab34d7561inmkl_set_num_threads__()from/../libmkl_intel_lp64.so获取线程数没问题:printmkl_rt.mkl_get_max_threads(

python - 类型错误 : expected a character buffer object

我在将值写入文件时遇到以下错误。你能帮我弄清楚这里的问题是什么以及如何解决吗?row=649withopen(r'\\loc\dev\Build_ver\build_ver.txt','r+')asf:f.write(row)printrow错误:Traceback(mostrecentcalllast):File"latest_rev.py",line6,inf.write(row)TypeError:expectedacharacterbufferobject 最佳答案 假设您只想将字符串'649'写入文件,将row更改为'64

python - 如何在不使用 num2word 库的情况下将数字转换为单词?

我需要将1-99中的数字转换为单词。这是我到目前为止得到的:num2words1={1:'One',2:'Two',3:'Three',4:'Four',5:'Five',\6:'Six',7:'Seven',8:'Eight',9:'Nine',10:'Ten',\11:'Eleven',12:'Twelve',13:'Thirteen',14:'Fourteen',\15:'Fifteen',16:'Sixteen',17:'Seventeen',18:'Eighteen',19:'Nineteen'}num2words2=['Twenty','Thirty','Forty','F

python - CSV 读取错误 : new-line character seen in unquoted field

我创建了一个python脚本,它使用包含10条记录的测试CSV数据集。当我将其扩展到实际数据集(几千行)时,出现以下错误:_csv.Error:new-linecharacterseeninunquotedfield-doyouneedtoopenthefileinuniversal-newlinemode?代码如下:withopen('./Origins.csv','r')ascsvfile:reader=csv.DictReader(csvfile)origincoords=['{Y},{X}'.format(**row)forrowinreader]完整的错误代码是:Traceb

python - 统一码编码错误 : 'ascii' codec can't encode character u'\xe4'

我一直收到以下错误:UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\xe4'inposition27:ordinalnotinrange(128)我已经试过了x.encode("ascii","ignore")x.encode("utf-8")x.decode("utf-8")然而,没有任何效果。 最佳答案 你必须在源头发现这个字符是用什么编码的。我猜这是ISO-8859-1(欧洲语言),在这种情况下它是“ä”,但你应该检查一下。它也可以是西里尔字母或希腊字母。参见http