使用python3.5,base64库里面的encodestring()被换成了什么?
下面是代码,应该怎么修改呢?
middlewares.py
PROXIES = [
{'ip_port': '**.**.**.**:8080', 'user_pass': ''},
{'ip_port': '**.**.**.**:8080', 'user_pass': ''},
{'ip_port': '**.**.**.**:8080', 'user_pass': ''}
]
class ProxyMiddleware(object):
def process_request(self, request, spider):
proxy = random.choice(PROXIES)
if proxy['user_pass'] is not None:
request.meta['proxy'] = "http://%s" % proxy['ip_port']
encoded_user_pass = base64.encodestring(proxy['user_pass'])
request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass
print("**************ProxyMiddleware have pass************" + proxy['ip_port'])
else:
print("**************ProxyMiddleware no pass************" + proxy['ip_port'])
request.meta['proxy'] = "http://%s" % proxy['ip_port']