genotrance / px

An HTTP proxy server to automatically authenticate through an NTLM proxy
MIT License
936 stars 99 forks source link

Python 3.9 has removed the deprecated base64.encodestring methods breaking px #116

Closed szaniec closed 2 years ago

szaniec commented 3 years ago

px fails to run using Python 3.9 due to the use of base64.encodestring in lines 317 and 329 of px.py.

Changing these to base64.encodebytes(string) fixes the issue.

Smixi commented 3 years ago

This PR fix those line: https://github.com/genotrance/px/pull/118

datadu-de commented 3 years ago

Hey, the PR seems to be merged, however I still have the same problem

PS C:\Python39\Scripts> .\px.exe
Serving at :3128 proc MainProcess
Serving at :3128 proc Process-1
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 60455)
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\px.py", line 327, in get_response_sspi
    response_msg = base64.encodebytes(response_msg.encode("utf-8"))
AttributeError: 'bytes' object has no attribute 'encode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python39\lib\socketserver.py", line 683, in process_request_thread
    self.finish_request(request, client_address)
  File "c:\python39\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\python39\lib\http\server.py", line 653, in __init__
    super().__init__(*args, **kwargs)
  File "c:\python39\lib\socketserver.py", line 747, in __init__
    self.handle()
  File "c:\python39\lib\http\server.py", line 427, in handle
    self.handle_one_request()
  File "c:\python39\lib\site-packages\px.py", line 356, in handle_one_request
    httpserver.SimpleHTTPRequestHandler.handle_one_request(self)
  File "c:\python39\lib\http\server.py", line 415, in handle_one_request
    method()
  File "c:\python39\lib\site-packages\px.py", line 680, in do_GET
    resp = self.do_transaction()
  File "c:\python39\lib\site-packages\px.py", line 601, in do_transaction
    ntlm_resp = ntlm.get_response()
  File "c:\python39\lib\site-packages\px.py", line 329, in get_response_sspi
    response_msg = base64.encodestring(response_msg)
AttributeError: module 'base64' has no attribute 'encodestring'
----------------------------------------
minecrawler commented 2 years ago

Hi, same problem as above. Tested with stable Px (px-proxy-0.4.0) and npm, and npm did not throw any errors, so I am not sure about the severity. It would be great if it did get fixed, though, since I am fed up with CNTLM always crashing and becoming unresponsive and aborting. At least Px works through one npm update with just a few errors popping up...

> px                                                                                                 
Serving at 127.0.0.1:3128 proc MainProcess
Serving at 127.0.0.1:3128 proc Process-1
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 65010)
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\px.py", line 327, in get_response_sspi
    response_msg = base64.encodebytes(response_msg.encode("utf-8"))
AttributeError: 'bytes' object has no attribute 'encode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python39\lib\socketserver.py", line 683, in process_request_thread
    self.finish_request(request, client_address)
  File "c:\python39\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\python39\lib\http\server.py", line 653, in __init__
    super().__init__(*args, **kwargs)
  File "c:\python39\lib\socketserver.py", line 747, in __init__
    self.handle()
  File "c:\python39\lib\http\server.py", line 427, in handle
    self.handle_one_request()
  File "c:\python39\lib\site-packages\px.py", line 356, in handle_one_request
    httpserver.SimpleHTTPRequestHandler.handle_one_request(self)
  File "c:\python39\lib\http\server.py", line 415, in handle_one_request
    method()
  File "c:\python39\lib\site-packages\px.py", line 723, in do_CONNECT
    resp = self.do_transaction()
  File "c:\python39\lib\site-packages\px.py", line 601, in do_transaction
    ntlm_resp = ntlm.get_response()
  File "c:\python39\lib\site-packages\px.py", line 329, in get_response_sspi
    response_msg = base64.encodestring(response_msg)
AttributeError: module 'base64' has no attribute 'encodestring'
----------------------------------------

This error just keeps spamming in the console, but Px stays responsive...

genotrance commented 2 years ago

Are you using a release binary downloaded from here? They are super old (2019) and recent PRs are not present. Can you retry with #head?

minecrawler commented 2 years ago

@genotrance

Are you using a release binary downloaded from here?

Yes, I followed the instructions for a stable installation using pip. I want to use Px for my work PC, hence prefer stable builds to get the job done. If it's so old and fixes are just waiting/waisting, maybe it's time for a new release? :)

Can you retry with #head?

I installed from git, and this time there are no errors when running npm. Thank you for your fast response!

Smixi commented 2 years ago

Well yeah, it seems binary are from 2019