账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    python3中错误'ascii' codec can't encode characters in position:
    30
    0
    searchValue = input('search:')
    url = url + searchValue
    req = request.Request(url)
    page = request.urlopen(req)
    bsObj = BeautifulSoup(page.read(), "lxml")
    print(bsObj)

    这是错误
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-15: ordinal not in range(128)

    刚刚在写这个,google了下并没有明确的答案

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 换我堕落ミ 普通会员 1楼

      The error message "ascii" codec can't encode characters in position: indicates that Python is unable to correctly decode a character that is not a valid ASCII character. The error message typically occurs when you are trying to encode a string that contains characters outside the ASCII range (0-127), or when you are working with text that has been encoded in a different character encoding format than ASCII.

      Here are a few common reasons why you might encounter this error:

      1. Encoded text not in ASCII format: If you are encoding text in a format that does not conform to ASCII, such as Unicode, you may encounter this error. Unicode is a global character encoding standard that extends ASCII to include additional characters beyond the basic 128 characters. If you are working with a text that uses a non-ASCII encoding, such as UTF-8 or UTF-16, you need to ensure that the text you are encoding is encoded in ASCII format or has a compatible encoding that supports Unicode characters.

      2. Unicode characters outside the ASCII range: Some Unicode characters, such as non-ASCII characters like accented letters or symbols, may not be included in the ASCII range. These characters are represented using Unicode code points outside the range of 0-127, and the ASCII codec does not have a built-in mapping for these characters. To encode a Unicode character, you need to use a character encoding that supports Unicode characters and convert it to an ASCII character first.

      3. Incorrect encoding of Unicode text: If you are working with text that has been encoded in a different character encoding format than ASCII, such as UTF-8, you need to ensure that you are using the correct encoding when encoding the text. UTF-8 is a widely supported character encoding format that uses UTF-16 surrogate pairs to represent Unicode characters. If you are using a different character encoding, such as ASCII or ISO-8859-1, you need to ensure that the text you are encoding has been encoded in the correct format and that you have a mapping between the ASCII characters and the corresponding UTF-8 characters.

      Here's an example code snippet that demonstrates how to encode a Unicode character in ASCII using Python 3:

      ```python import unicodedata

      Unicode character to encode

      unicode_char = "

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部