Repository navigation
[BUG] ValueError: too many values to unpack (expected 2) #20
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The proxy works fine for HTTP.
For HTTPS I get an error: ValueError: too many values to unpack (expected 2)
To Reproduce
Steps to reproduce the behavior:
mkvirtualenv pyproxypip install pyproxytoolsmkdir configtouch config/blocked_sites.txtpython3 -m pyproxy
In another terminal use:
$ https_proxy=0.0.0.0:8080 curl https://www.free.fr
curl: (35) Send failure: Broken pipe
Configuration used
No configuration. I use an empty config/blocked_sites.txt file
Expected behavior
I get the https page
Logs
$ python3 -m pyproxy --debug
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=Configuration used:
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] allowed_subnets = None
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] config_custom_header = config/custom_header.json
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] config_shortcuts = config/shortcuts.txt
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] debug = True
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] filter_config = ProxyConfigFilter(no_filter=False, filter_mode='local', blocked_sites='config/blocked_sites.txt', blocked_url='config/blocked_url.txt')
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] host_port = ('0.0.0.0', 8080)
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] html_403 = assets/403.html
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] logger_config = ProxyConfigLogger(access_log='logs/access.log', block_log='logs/block.log', no_logging_access=False, no_logging_block=False, console_format='date=%(asctime)s level=%(levelname)s file=%(filename)s function=%(funcName)s message=%(message)s', access_log_format='date=%(asctime)s ip_src=%(ip_src)s url=%(url)s method=%(method)s domain=%(domain)s port=%(port)s protocol=%(protocol)s bytes_sent=%(bytes_sent)s bytes_received=%(bytes_received)s tls_version=%(tls_version)s', block_log_format='date=%(asctime)s ip_src=%(ip_src)s url=%(url)s method=%(method)s domain=%(domain)s port=%(port)s protocol=%(protocol)s', datefmt='%Y-%m-%d %H:%M:%S')
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] monitoring_config = ProxyConfigMonitoring(flask_port=5000, flask_pass='password')
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] proxy_config = ProxyConfigProxy(enable=False, host='127.0.0.1', port=8081)
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=start message=[*] ssl_config = ProxyConfigSSL(ssl_inspect=False, inspect_ca_cert='certs/ca/cert.pem', inspect_ca_key='certs/ca/key.pem', inspect_certs_folder='certs/', cancel_inspect='config/cancel_inspect.txt')
date=2026-04-30 11:12:50 level=DEBUG file=server.py function=_initialize_processes message=[*] Starting the filter process...
date=2026-04-30 11:12:50 level=INFO file=server.py function=start message=Proxy server started on ('0.0.0.0', 8080)...
date=2026-04-30 11:12:53 level=DEBUG file=server.py function=start message=Connection from ('127.0.0.1', 38550)
Exception in thread Thread-1 (handle_client):
Traceback (most recent call last):
File "/usr/lib/python3.13/threading.py", line 1043, in _bootstrap_inner
self.run()
~~~~~~~~^^
File "/usr/lib/python3.13/threading.py", line 994, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lroussea/.virtualenvs/pyproxy/lib/python3.13/site-packages/pyproxy/handlers/client.py", line 108, in handle_client
https_handler.handle_https_connection(client_socket, first_line)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lroussea/.virtualenvs/pyproxy/lib/python3.13/site-packages/pyproxy/handlers/https.py", line 327, in handle_https_connection
bytes_sent, bytes_received = self.transfer_data_between_sockets(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
client_socket, server_socket
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/home/lroussea/.virtualenvs/pyproxy/lib/python3.13/site-packages/pyproxy/handlers/https.py", line 380, in transfer_data_between_sockets
target_ip, target_port = server_socket.getpeername()
^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)
Additional context
Add any other context about the problem here.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
LudovicRousseau commentedon Apr 30, 2026
The problem is that
server_socket.getpeername()returns 4 elements instead of 2.I added a call to
print()and I get:('2a01:e0c:1::1', 443, 0, 0)I very simple (maybe stupid) patch is:
LudovicRousseau commentedon Apr 30, 2026
Note: I am using Debian trixie, so with Python 3.13.5
fix: handle IPv6 getpeername tuple (#20)
6C656C65 commentedon Apr 30, 2026
Thanks for reporting this issue.
After investigation, this behavior is due to the proxy's WAN configuration. The server socket is using the
AF_INET6address family, which means thatgetpeername()returns a 4-element tuple instead of the usual 2-element tuple seen with IPv4.This is expected and documented in Python’s socket documentation:
https://docs.python.org/3/library/socket.html#socket-families
A fix has been implemented in #22. Could you please try it out and confirm if it resolves the issue? I’ll proceed with merging once it’s validated.
LudovicRousseau commentedon May 5, 2026
The patch in #22 fixes the problem after a small change. I added a comment in the PR.
fix: remove old line (#20)
fix: handle IPv6 getpeername tuple (#20) (#22)
6C656C65 commentedon May 6, 2026
I merged
fix/20, the fix is available in version0.5.2