python - PySocks proxy auhtentication failed -


i'm still try create imap\pop3 proxied client. first try on php here. try same python.

i found answer, fits, code based on stackowerflow answer , work proxy without authentication:

class socksimap4ssl(imap4_ssl):     def open(self, host, port=imap4_ssl_port):         self.host = host         self.port = port         self.sock = create_connection(dest_pair=(host, port), proxy_type=proxy_type_http, proxy_addr=proxy_ip,                                       proxy_port=proxy_port, proxy_rdns=true, proxy_username=proxy_auth_login,                                       proxy_password=proxy_auth_pass)         # self.sock = socket.create_connection((host, port))         self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)         self.file = self.sslobj.makefile('rb') 

but if use proxy authentication fail reason:

socks.httperror: 407: proxy authentication required 

proxy auth type: basic. both login , password correct. doing wrong?

i used https://github.com/anorov/pysocks, not support basic authentication http proxy. few lines solves issue:

http_headers = [     b"connect %s:%s http/1.1" % (addr.encode('idna'), str(dest_port).encode()),     b"host: %s" % dest_addr.encode('idna') ]  if username , password:     http_headers.append(b"proxy-authorization: basic %s" % str(b64encode("%s:%s" % (username, password))))  http_headers.append(b"\r\n")  self.sendall(b"\r\n".join(http_headers)) 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -