Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-unicode chars in url #3

Open
wants to merge 1 commit into
base: python3
Choose a base branch
from

Conversation

guysoft
Copy link

@guysoft guysoft commented Mar 20, 2018

If a url has a non-unicode path, then the proxy crashes with:

Exception happened during processing of request from ('::ffff:127.0.0.1', 34814, 0, 0)
Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "./proxy2.py", line 63, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "/usr/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
    method()
  File "./proxy2.py", line 210, in do_GET
    self.save_handler(req, req_body, res, res_body_plain)
  File "./proxy2.py", line 379, in save_handler
    self.print_info(req, req_body, res, res_body)
  File "./proxy2.py", line 318, in print_info
    req_body_text = parse_qsl(req_body)
  File "./proxy2.py", line 291, in parse_qsl
    return '\n'.join("{:<20} {}".format(k, v) for k, v in urlparse.parse_qsl(s, keep_blank_values=True))
  File "/usr/lib/python3.6/urllib/parse.py", line 703, in parse_qsl
    value = _coerce_result(value)
  File "/usr/lib/python3.6/urllib/parse.py", line 103, in _encode_result
    return obj.encode(encoding, errors)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 13-32: ordinal not in range(128)

I found that sometimes the information in parse is a string, and sometimes its bytes, this solves the problem.

@Nikolaev-Nikolay
Copy link

It is ok, but {!s:<20}

def print_info(self, req, req_body, res, res_body):
def parse_qsl(s):
if type(s) == bytes:
return '\n'.join("{!s:<20} {}".format(k, v) for k, v in urlparse.parse_qsl(s, keep_blank_values=True))
else:
return '\n'.join("{!s:<20} {}".format(k, v) for k, v in urlparse.parse_qsl(s.decode("utf-8"), keep_blank_values=True))

@guysoft
Copy link
Author

guysoft commented Oct 20, 2018

Would that change get this merged? Looks like there is no activity here. I submitted this months ago.

You are wwelcome to PR from my fork.

@Nikolaev-Nikolay
Copy link

I need to make a queue for messages from a parallel running program (python processes). Messages should go through a proxy to one external server. Server responses are also distributed according to the call queue. I want to do on RabbitMQ. Help me find the entry point in the PROXY2 code to send to RabbitMQ and an external server. And accepted answers in the same order. Thank you!

@guysoft
Copy link
Author

guysoft commented Oct 21, 2018

Ok, I opend issue tracker at https://github.com/guysoft/proxy2/issues

Please post there since this repository is evidently abounded

(only sign of life is @inaz2 👍 a while ago)

@guysoft
Copy link
Author

guysoft commented Jul 12, 2020

@hubald I see your fork is actually maintaining this. Can you open the Issue tracker and PR so we can move development there?

@guysoft
Copy link
Author

guysoft commented Jul 15, 2020

Thanks @hubald , continued in https://github.com/Hubald/proxy2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants