草庐IT

mb_encode_numericentity

全部标签

python - 统一码编码错误 : 'ascii' codec can't encode character u'\u2019' in position 6: ordinal not in range(128)

我正在尝试从TripAdvisor中提取阿姆斯特丹500家餐厅的列表;然而,在第308家餐厅之后,我收到以下错误:Traceback(mostrecentcalllast):File"C:/Users/dtrinh/PycharmProjects/TripAdvisorData/LinkPull-HK.py",line43,inwriter.writerow(rest_array)UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\u2019'inposition6:ordinalnotinrange(128)我尝试了一些在Sta

python - PySpark — UnicodeEncodeError : 'ascii' codec can't encode character

使用spark.read.csv和encoding='utf-8'将包含外来字符(åäö)的数据帧加载到Spark中,并尝试做一个简单的展示().>>>df.show()Traceback(mostrecentcalllast):File"",line1,inFile"/usr/lib/spark/python/pyspark/sql/dataframe.py",line287,inshowprint(self._jdf.showString(n,truncate))UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\ufffd'

Python Pandas to_clipboard() UnicodeEncodeError : 'ascii' codec can't encode character

我想将数据框数据传递到剪贴板,以便粘贴到Excel中。问题是,字符'\xe9'导致编码问题,如下所示:>>>df.to_clipboard()Traceback(mostrecentcalllast):File"C:\Python34\lib\site-packages\pandas\util\clipboard.py",line65,inwinSetClipboardhCd=ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE,len(bytes(text))+1)TypeError:stringargumentwithoutanencod

python转换编码:LookupError: unknown encoding: ansi

因为我的cdv文件编码为utf-8,用Excel打开会出现乱码,再转成标准的ANSI编码时,我得到这个错误:代码:importchardetdefconvertEncoding(from_encode,to_encode,old_filepath,target_file):f1=file(old_filepath)content2=[]whileTrue:line=f1.readline()content2.append(line.decode(from_encode).encode(to_encode))iflen(line)==0:breakf1.close()f2=file(ta

python - 将巨大的(95Mb)JSON 数组拆分成更小的 block ?

我以JSON的形式从我的数据库中导出了一些数据,它本质上只是一个[列表],里面有一堆(900K){objects}。现在正在尝试将它导入我的生产服务器,但我有一些便宜的网络服务器。他们不喜欢我在10分钟内吃掉他们所有的资源。如何将这个文件拆分成更小的block,以便我可以逐个导入它?编辑:实际上,它是一个PostgreSQL数据库。我愿意接受有关如何分block导出所有数据的其他建议。我在我的服务器上安装了phpPgAdmin,它应该可以接受CSV、Tabbed和XML格式。我必须修复phihag的脚本:importjsonwithopen('fixtures/PostalCodes.

python - Pandas to_csv : ascii can't encode character

我正在尝试读取数据帧并将其写入管道分隔文件。一些字符是非罗马字母(`、ç、ñ等)。但是,当我尝试将重音符号写为ASCII时,它就崩溃了。df=pd.read_csv('filename.txt',sep='|',encoding='utf-8')newdf.to_csv('output.txt',sep='|',index=False,encoding='ascii')-------File"",line21,innewdf.to_csv(filename,sep='|',index=False,encoding='ascii')File"C:\Users\aliceell\AppDa

python - 如何在 Python 中编码 (utf8mb4)

如何在Python中对ut8mb4中的内容进行编码?我有两组数据:我正在从Parse迁移到我的新MySQL数据库的数据,以及future的数据(仅与我的新数据库对话)。我的数据库是utf8mb4以存储表情符号和带重音符号的字母。只有在我的python脚本中,第一组数据才能正确显示(当涉及表情符号和口音时):MySQLdb.escape_string(unicode(xstr(data.get('message'))).encode('utf-8'))当用PHP读取MySQL数据库时:$row["message"]=utf8_encode($row["message"]);只有当我不包含

python - Ubuntu、Apache2、Django)致命的 Python 错误 : Py_Initialize: Unable to get the locale encoding ImportError: No module named 'encodings'

我正在尝试使用具有Ubuntu14.04、Apache2、python3.4的AWSEC2设置我的django(1.8)应用程序。当我运行“sudoserviceapache2start”时,页面不断重新加载并且相同的错误消息堆积在“/var/log/apache2/error.log”中。错误信息是[FriAug262016][mpm_event:notice][pidn:tidm]AH00489:Apache/2.4.7(Ubuntu)mod_wsgi/4.5.5Python/3.4.3configured--resumingnormaloperations[FriAug26201

python - 为什么 sys.getdefaultencoding() 与 sys.stdout.encoding 不同?这如何破坏 Unicode 字符串?

我花了几个愤怒的时间寻找Unicode字符串的问题,这些字符串被分解为Python(2.7)对我隐藏的东西,但我仍然不明白。首先,我尝试在我的代码中始终使用u".."字符串,但这导致了臭名昭著的UnicodeEncodeError。我尝试使用.encode('utf8'),但这也无济于事。最后,事实证明我不应该使用任何一个,这一切都会自动解决。然而,我(在这里我需要感谢一位帮助过我的friend)在用头撞墙时确实注意到了一些奇怪的事情。sys.getdefaultencoding()返回ascii,而sys.stdout.encoding返回UTF-8。1.在下面的代码中工作正常,无需

python - urlsafe_b64encode 总是以 '=' 结尾? :

我认为这一定是一个愚蠢的问题,但为什么urlsafe_b64encode()的结果对我来说总是以“=”结尾?'='网址不安全吗?fromrandomimportgetrandbitsfrombase64importurlsafe_b64encodefromhashlibimportsha256fromtimeimportsleepdefgenKey():keyLenBits=64a=str(getrandbits(keyLenBits))b=urlsafe_b64encode(sha256(a).digest())printbwhile1:genKey()sleep(1)输出:DxFO