raw_input()不等待用户输入

时间:2015-03-19 16:51:20

标签: python

raw_input我遇到了一个奇怪的问题。它似乎没有等待用户输入。这是失败的方法:

def displayCaptcha(self):
    url = 'https://www.google.com/recaptcha/api/challenge?k=xxxxxxxx'

    r = requests.get(url)
    m = re.search("challenge : '(.+)'", r.text)

    if not m:
        raise Exception('Could not fetch ReCaptcha challange code')

    c = m.groups(0)

    # Fetch the captcha image from Google's servers
    r = requests.get("https://www.google.com/recaptcha/api/image?c=%s" % c)
    Image.open(StringIO(r.content)).show()
    captchaResponse = raw_input('Enter Captcha: ')

    # Problem!
    print 'This prints even before user has entered any key'

    return c, captchaResponse

输出:

God@War:$ echo "190106193" | ./liker.py username password
Enter Captcha: This prints even before user has entered any key
Login failed. Exiting ...

奇怪的是它工作正常。我写了代码,现在它难倒了我。但是,从我所看到的print之后raw_input不应该在用户输入密钥之前打印,所以看起来我的问题就在这里。

有什么想法吗?

哪个电话......

try:
    r = self.login()
except CaptchaError:
    # Login failed site requesting captcha
    r = self.loginWithCaptcha()

# If login wasn't successful, return
if not r:
    return False

# Login is successful, set login status to True, fetch
# the users OAuth token
self.loggedIn = True
self.token = self.getOauthToken()

# Save the session to disk so the user hasn't got to
# login each time.
self.saveSession()

return True

0 个答案:

没有答案
相关问题