0

我有以下代码:

# -*- coding: utf-8 -*-
import splinter
import urllib

browser = splinter.Browser('firefox')

miss = ("rúin",)

for i in miss:
    browser.visit(link)
    browser.fill('word', i)

这给了我错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)

我该如何解决这个问题?

4

1 回答 1

1

Use an actual unicode value:

miss = (u"rúin",)

Note the u before the string literal.

Python otherwise will try to coerce the bytestring to unicode implicitly, using the default codec (ASCII).

于 2013-12-29T16:58:19.003 回答