我很难通过他们的Python API将我的验证码文件发送给死亡通过Captcha,但我不知道在哪里放置我的用户名和密码。
每次我运行代码时,无论我在哪里放置真实凭证,它都会给我这个错误。
Traceback (most recent call last):
File "/home/xsk/Desktop/py.projects/pycap/acc1.py", line 72, in <module>
client = deathbycaptcha.SocketClient(username, password)
NameError: name 'username' is not defined
[Finished in 34.2s]
首先我从DBC获得这个例子,但我不确定是否必须在此处输入我的用户名和密码以及验证码图像和超时,或者我必须放入deathbycaptcha.py文件。
来自DBC的示例
###############DEATHBY CAPTCHA######################
####################################################
import deathbycaptcha
# Put your DBC account username and password here.
# Use deathbycaptcha.HttpClient for HTTP API.
client = deathbycaptcha.SocketClient(username, password)
try:
balance = client.get_balance()
# Put your CAPTCHA file name or file-like object, and optional
# solving timeout (in seconds) here:
captcha = client.decode(captcha_file_name, timeout)
if captcha:
# The CAPTCHA was solved; captcha["captcha"] item holds its
# numeric ID, and captcha["text"] item its text.
print "CAPTCHA %s solved: %s" % (captcha["captcha"], captcha["text"])
if captcha: # check if the CAPTCHA was incorrectly solved
client.report(captcha["captcha"])
except deathbycaptcha.AccessDeniedException:
# Access to DBC API denied, check your credentials and/or balance
####################################################
deathbycaptcha.py片段
class Client(object):
"""Death by Captcha API Client."""
def __init__(self, username, password):
self.is_verbose = False
self.userpwd = {'username': username, 'password': password}
def _log(self, cmd, msg=''):
if self.is_verbose:
print '%d %s %s' % (time.time(), cmd, msg.rstrip())
return self
def close(self):
pass
def connect(self):
pass
那么请任何人帮助我了解如何设置DBC API?谢谢。