'UCS-2' codec can't encode characters in position
前幾天在寫python程式時,遇到了以上問題,在Stackovereflow上找到了解決方案,記錄一下:
Your data contains characters outside of the Basic Multilingual Plane. Emoji's for example, are outside the BMP, and the window system used by IDLE, Tk, cannot handle such characters.
也就是說,開啟的文件中含有BMP基本多文種字面之外的字元,需要以下的程式碼來包含BMP之外的字元:
Theimport sys non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd) print(x.translate(non_bmp_map))
non_bmp_map
maps
all codepoints outside the BMP (any codepoint higher than 0xFFFF, all the way up to the highest
Unicode codepoint your Python version can handle) to U+FFFD
REPLACEMENT CHARACTER:
test測試:
>>> print('This works! \U0001F44D')
This works!
相關推薦
'UCS-2' codec can't encode characters in position
前幾天在寫python程式時,遇到了以上問題,在Stackovereflow上找到了解決方案,記錄一下: Your data contains characters outside of the Basic Multilingual Plane. Emoji's fo
macOS解決sublime text3執行python3報:UnicodeEncodeError: 'ascii' codec can't encode characters in position
問題背景:macOS剛裝上python3和sublime test,匯入原來在windows上寫的python指令碼(在windows上執行正常),執行後報錯UnicodeEncodeError: 'ascii' codec can't encode characters i
解決 UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-20: ordinal not in range
python中因編碼問題報錯: Traceback (most recent call last): File "a*.py", line 61, in <module> m*w
python 字串輸出報錯 'utf-8' codec can't encode characters in position
一些字串無法被utf-8解碼,所以可以把無法轉化為utf-8格式的字元‘ignore’掉,再進行解碼。 str().encode('UTF-8', 'ignore').decode('UTF-8') 測試程式碼: text = ''' '\n
python中文編碼問題解決UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-14: ordinal n
編碼報錯: https://www.baidu.com/s?wd=渴望飛的魚 UnicodeEncodeError: 'ascii' codec can't encode characters in
python 編碼問題:'ascii' codec can't encode characters in position 的解決方案
報錯: 'ascii' codec can't encode characters in position 8-50: ordinal not in range(128) Python在安裝時,預設的編碼是ascii,當程式中出現非ascii編碼時,python的處理常常
Python問題: UnicodeEncodeError:'ascii' codec can't encode characters in position
在Windows、Python2.7下寫入txt檔案時發現報錯了,報錯資訊如下: UnicodeEncodeError: 'ascii' codec can't encode characters i
Django——報錯:admin後臺新增中文資料時報錯——UnicodeEncodeError: 'ascii' codec can't encode characters in position..
這個是在弄自己的個人部落格站點時遇到的問題,在admin後臺新增中文資料時,會報錯:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3 解決辦法,在相應的admin.py(專案/
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-15: ordinal not in range(128
有2種方法設定python的預設編碼: 一個解決的方案在程式中加入以下程式碼: Python程式碼 import sys reload(sys) sys.setdefaultencoding('utf8') 另一個方案是在python的Lib\site-packa
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128
寫django報如下錯誤: File "C:\Python27\MyDjango\jianzhi_002\jianzhi_app\models.py", line 391, in __unic
解決UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range
字串在Python內部的表示是unicode編碼,因此,在做編碼轉換時,通常需要以unicode作為中間編碼,即先將其他編碼的字串解碼(decode)成unicode,再從unicode編碼(encode)成另一種編碼。 Decode的作用是將其他編碼的字串轉換成
解決UnicodeEncodeError: 'ascii' codec can't encode characters in position問題
在開頭加上 import sys reload(sys) sys.setdefaultencoding( “utf-8” ) Python自然呼叫ascii編碼解碼程式去處理字元流,當字元流不屬於ascii範圍內,就會丟擲異常(ordinal not i
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position xxx ordinal not in range(12
python在安裝時,預設的編碼是ascii,當程式中出現非ascii編碼時,python的處理常常會報這樣的錯UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal
UnicodeEncodeError:'utf-8' codec can't encode characters in position 380-382: surrogates not allowed
考慮是某些字元無法解碼為utf-8的編碼格式,把dataframe(meta)的元素,在編碼過程中,先把無法轉化為utf-8格式的字元‘ignore’掉,再進行解碼。for i in meta: for j in meta.index: meta.lo
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)
Python在處理中文編碼時經常會出現亂碼,並報如標題那樣的錯誤,這時只要在程式碼起始處加入如下程式碼即可解決: import sys reload(sys) sys.setdefaultenco
[漢字編碼報錯] UnicodeEncodeError- 'ascii' codec can't encode characters in position 0-1- ordinal not in r
原始程式碼 # -*- coding:utf-8 -*- import pandas as pd import jieba def cut_msg(ustr): # ustr = ust
python3 執行出現'ascii' codec can't encode characters in position 10-11: ordinal not in range(128)錯誤解決方案
‘ascii’ codec can’t encode characters in position 10-11: ordinal not in range(128) 最近,部署測試環境時新啟用了一臺U
UnicodeEncodeError: 'ascii' codec can't encode characters in 解決辦法
編寫程式碼的時候出現:UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position… 很明顯是編碼的問題,然而檢查了一下,coding都是設定的utf-8的編碼格式,依然報錯,沒辦法
'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
問題 rds_content = "{}, 執行了變更,sql語句:{}".format(ExecuteTime, sqls) 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) 解決方法:
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)
clas mysq mic swd pass pan 天使 -1 root 今天使用MySQLdb往MySQL插入中文數據遇到一個異常: UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters in posit