使用python3.5,base64库里面的encodestring()被换成了什么?

使用python3.5,base64库里面的encodestring()被换成了什么?

clipboard.png

下面是代码,应该怎么修改呢?

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']
阅读 15.5k
1 个回答
#coding=utf-8
import base64

#编码
encodestr = base64.b64encode("1234".encode(encoding='utf-8'))
print(encodestr) # 注意encodestr类型是byte,不是str
print(encodestr.decode())

#解码
decodestr = base64.b64decode(encodestr)
print(decodestr.decode())
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏