Skip to content

[BUG] ValueError: too many values to unpack (expected 2) #20

Closed

Description

@LudovicRousseau

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:

  1. mkvirtualenv pyproxy
  2. pip install pyproxytools
  3. mkdir config
  4. touch config/blocked_sites.txt
  5. python3 -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.

Activity

  1. LudovicRousseau commented on Apr 30, 2026

    @LudovicRousseau
    Author

    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:

    --- https.py.old	2026-04-30 11:19:00.993996181 +0200
    +++ https.py	2026-04-30 11:19:08.249898820 +0200
    @@ -377,7 +377,7 @@
                 and "target_ip" not in self.active_connections[thread_id]
             ):
                 try:
    -                target_ip, target_port = server_socket.getpeername()
    +                target_ip, target_port = server_socket.getpeername()[2:]
                     self.active_connections[thread_id]["target_ip"] = target_ip
                     self.active_connections[thread_id]["target_port"] = target_port
                 except OSError as e:
  2. LudovicRousseau commented on Apr 30, 2026

    @LudovicRousseau
    Author

    Note: I am using Debian trixie, so with Python 3.13.5

  3. 6C656C65 commented on Apr 30, 2026

    @6C656C65
    Member

    Thanks for reporting this issue.

    After investigation, this behavior is due to the proxy's WAN configuration. The server socket is using the AF_INET6 address family, which means that getpeername() 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.

  4. LudovicRousseau commented on May 5, 2026

    @LudovicRousseau
    Author

    The patch in #22 fixes the problem after a small change. I added a comment in the PR.

  5. 6C656C65 commented on May 6, 2026

    @6C656C65
    Member

    I merged fix/20, the fix is ​​available in version 0.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions