我尝试运行代码时收到此错误:
File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 1118, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>
Run Code Online (Sandbox Code Playgroud)
我在Windows 8.1上运行它,我可以打开https请求没有问题,但是如果我使用mechanize我就会得到错误.我的代码:
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17')]
sign_in = br.open('https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fcss%2Fhomepage.html%3Fie%3DUTF8%26ref_%3Dnav_yam_ya')
br.select_form(name="signIn")
br["email"] = 'username'
br['password'] = 'password'
logged_in = br.submit()
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用rabbitmq 获得一个基本的队列系统,但是当我尝试使用线程时,它似乎只运行了 1 个线程。
我的代码:
import pika
import threading
rabbit_url = "amqp://user:pass!@127.0.0.1:5672/%2f"
def start(max_threads):
for i in xrange(max_threads):
t = threading.Thread(target=run)
t.start()
t.join()
def run():
connection = pika.BlockingConnection(pika.URLParameters(rabbit_url))
channel = connection.channel()
channel.basic_consume(callback,
queue='docketq',
no_ack=True)
channel.start_consuming()
def callback(ch, method, properties, body):
do_work(body)
def do_work(body):
print body
Run Code Online (Sandbox Code Playgroud)