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

TypeError: wrap_socket() missing 1 required positional argument: 'sock' #345

Closed
tbarbugli opened this issue Aug 22, 2018 · 12 comments
Closed

TypeError: wrap_socket() missing 1 required positional argument: 'sock' #345

tbarbugli opened this issue Aug 22, 2018 · 12 comments

Comments

@tbarbugli
Copy link

@tbarbugli tbarbugli commented Aug 22, 2018

I am getting this error since the release of 0.9.5. This happens on Python 2.7, 3.4, 3.5 and 3.6.

Here's the stack-trace:

Traceback (most recent call last):
  File "/home/travis/build/GetStream/stream-django/.eggs/httpretty-0.9.5-py3.6.egg/httpretty/core.py", line 1636, in wrapper
    return test(*args, **kw)
  File "/home/travis/build/GetStream/stream-django/stream_django/tests/test_app/tests/test_manager.py", line 48, in test_unfollow_user
    feed_manager.unfollow_user(1, 2)
  File "/home/travis/build/GetStream/stream-django/stream_django/managers.py", line 49, in unfollow_user
    feed.unfollow(target_feed.slug, target_feed.user_id)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/stream/feed.py", line 166, in unfollow
    response = self.client.delete(url, signature=token, params=params)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/stream/client.py", line 271, in delete
    return self._make_request(self.session.delete, *args, **kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/stream/client.py", line 210, in _make_request
    params=default_params, timeout=self.timeout)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/requests/sessions.py", line 591, in delete
    return self.request('DELETE', url, **kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/urllib3/connection.py", line 356, in connect
    ssl_context=context)
  File "/home/travis/build/GetStream/stream-django/.eggs/httpretty-0.9.5-py3.6.egg/httpretty/core.py", line 600, in fake_wrap_socket
    return orig_wrap_socket_fn(*args, **kw)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 359, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/home/travis/build/GetStream/stream-django/.eggs/httpretty-0.9.5-py3.6.egg/httpretty/core.py", line 600, in fake_wrap_socket
    return orig_wrap_socket_fn(*args, **kw)
TypeError: wrap_socket() missing 1 required positional argument: 'sock'

This is happening on a public Github project during Travis (https://travis-ci.org/GetStream/stream-django/builds).

@nijel

This comment has been minimized.

Copy link

@nijel nijel commented Aug 28, 2018

I can see this as well, on Python 2.7 the error is different though:

  File "/home/nijel/.local/lib/python2.7/site-packages/httpretty/core.py", line 600, in fake_wrap_socket
    return orig_wrap_socket_fn(*args, **kw)
TypeError: unbound method wrap_socket() must be called with SSLContext instance as first argument (got socket instance instead)
@nijel

This comment has been minimized.

Copy link

@nijel nijel commented Aug 28, 2018

...and this only happens when given URL is not mocked (in my case it was bug in test, which was not spot as it was testing error handling, so it was expected that the request will fail).

nijel added a commit to WeblateOrg/weblate that referenced this issue Aug 28, 2018
Found thanks to gabrielfalcao/HTTPretty#345

Signed-off-by: Michal Čihař <michal@cihar.com>
@kalkehcoisa

This comment has been minimized.

Copy link

@kalkehcoisa kalkehcoisa commented Sep 7, 2018

I stumbled on this error as well. It happens in this method:

def fake_wrap_socket(orig_wrap_socket_fn, *args, **kw):
    """drop-in replacement for py:func:`ssl.wrap_socket`
    """
    server_hostname = kw.get('server_hostname')
    if server_hostname is not None:
        matcher = httpretty.match_https_hostname(server_hostname)
        if matcher is None:
                return orig_wrap_socket_fn(*args, **kw)
    if 'sock' in kw:
        return kw['sock']
    else:
        return args[0]

Checking around, I found out that the problem comes from line 1491:

ssl.SSLContext.wrap_socket = partial(fake_wrap_socket, old_sslcontext_wrap_socket)

ssl.SSLContext.wrap_socket is a class method and has a self param that partial ignores completely. It should use functools.partialmethod and apply the instance ssl.SSLContext properly around. As it is, the call on line 600 is attributing the fake sock and causing the error.
I tried fixing this way. Sock missing was solved. BUT, the lib got stuck. It didn't break, nor answered a thing.

So, there must be something more here.

@PClmnt

This comment has been minimized.

Copy link

@PClmnt PClmnt commented Oct 30, 2018

@kalkehcoisa Did you ever get a fix for this? I'm seeing the same issue on Python 2.7.15.

It seems to happen for me even when the URL is correct, in contrast to what @nijel had seen.

@jsyvino

This comment has been minimized.

Copy link

@jsyvino jsyvino commented Dec 20, 2018

@kalkehcoisa I am also running into this issue

@KyleJamesWalker

This comment has been minimized.

Copy link

@KyleJamesWalker KyleJamesWalker commented Jan 30, 2019

I had the same issue I had to install pyOpenSSL==18.0.0

Note: This does not fix HTTP requests, the library needs to be updated to work with the latest patterns it looks like.

@dmugtasimov

This comment has been minimized.

Copy link

@dmugtasimov dmugtasimov commented Mar 19, 2019

What is the status of this issue? I mean is it accepted as a bug?

@madchutney

This comment has been minimized.

Copy link

@madchutney madchutney commented Apr 3, 2019

I had this issue when the scheme (e.g. http://) was not defined in the mocked URL, adding the scheme resolved the issue for me.

@denizdogan

This comment has been minimized.

Copy link

@denizdogan denizdogan commented Jun 3, 2019

Any news on this issue? It's been a while and it's a bit of a blocker.

@DanielSCrouch

This comment has been minimized.

Copy link

@DanielSCrouch DanielSCrouch commented Jul 21, 2019

Any progress?

@ethagnawl

This comment has been minimized.

Copy link

@ethagnawl ethagnawl commented Nov 13, 2019

I'm running into this when using Google API client libraries. Has anyone else had this issue? Is there a known workaround?

@nabilm

This comment has been minimized.

Copy link

@nabilm nabilm commented Nov 17, 2019

@ethagnawl

I'm running into this when using Google API client libraries. Has anyone else had this issue? Is there a known workaround?

did you figure out anything around that ? i guess there's a problem with httpretty and the new v3 apis

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

Successfully merging a pull request may close this issue.

You can’t perform that action at this time.