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

urllib3>=2.3.0 breaks httpretty with allow_net_connect=False #484

Open
EnricoMi opened this issue Dec 28, 2024 · 0 comments
Open

urllib3>=2.3.0 breaks httpretty with allow_net_connect=False #484

EnricoMi opened this issue Dec 28, 2024 · 0 comments

Comments

@EnricoMi
Copy link

Problem is that urllib3 now calls into httpretty.core.fakesock.socket.__getattr__ with "shutdown", which raises an error with httpretty.enable(allow_net_connect=False):

________________ ApplicationOAuth.testEnterpriseGetAccessToken _________________
self = <tests.ApplicationOAuth.ApplicationOAuth testMethod=testEnterpriseGetAccessToken>
    def testEnterpriseGetAccessToken(self):
>       access_token = self.ent_app.get_access_token("oauth_code_removed", state="state_removed")
tests/ApplicationOAuth.py:107: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
github/ApplicationOAuth.py:137: in get_access_token
    *self._requester.requestJsonAndCheck(
github/Requester.py:586: in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
github/Requester.py:856: in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
github/Requester.py:977: in __requestEncode
    status, responseHeaders, output = self.__requestRaw(cnx, verb, url, requestHeaders, encoded_input)
github/Requester.py:1011: in __requestRaw
    response = cnx.getresponse()
tests/Framework.py:254: in getresponse
    response = self.__cnx.getresponse()
github/Requester.py:265: in getresponse
    r = verb(
/usr/lib/python3.13/site-packages/requests/sessions.py:637: in post
    return self.request("POST", url, data=data, json=json, **kwargs)
/usr/lib/python3.13/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
/usr/lib/python3.13/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)
/usr/lib/python3.13/site-packages/requests/adapters.py:668: in send
    resp = conn.urlopen(
/usr/lib/python3.13/site-packages/urllib3/connectionpool.py:787: in urlopen
    response = self._make_request(
/usr/lib/python3.13/site-packages/urllib3/connectionpool.py:534: in _make_request
    response = conn.getresponse()
/usr/lib/python3.13/site-packages/urllib3/connection.py:513: in getresponse
    _shutdown = getattr(self.sock, "shutdown", None)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = httpretty.core.socket("my.enterprise.com:80"), name = 'shutdown'
    def __getattr__(self, name):
        if name in ('getsockopt', 'selected_alpn_protocol') and not self.truesock:
            self.truesock = self.create_socket()
        elif httpretty.allow_net_connect and not self.truesock:
            # can't call self.connect_truesock() here because we
            # don't know if user wants to execute server of client
            # calls (or can they?)
            self.truesock = self.create_socket()
        elif not self.truesock:
            # Special case for
            # `hasattr(sock, "version")` call added in urllib3>=1.26.
            if name == 'version':
                raise AttributeError(
                    "HTTPretty synthesized this error to fix urllib3 compatibility "
                    "(see issue https://github.com/gabrielfalcao/HTTPretty/issues/409). "
                    "Please open an issue if this error causes further unexpected issues."
                )
    
>           raise UnmockedError('Failed to socket.{} because because a real socket does not exist'.format(name))
E           httpretty.errors.UnmockedError: Failed to socket.shutdown because because a real socket does not exist
E           
E           Tip: You could try setting (allow_net_connect=True) to allow unregistered requests through a real TCP connection in addition to (verbose=True) to debug the issue.
/usr/lib/python3.13/site-packages/httpretty/core.py:894: UnmockedError

PyGithub/PyGithub#3101

offbyone added a commit to offbyone/social-core that referenced this issue Jan 2, 2025
adacore-bot pushed a commit to AdaCore/e3-core that referenced this issue Jan 3, 2025
Set urllib to 2.2.3 version as the new version 2.3.0 breaks httpretty

see gabrielfalcao/HTTPretty#484
nijel added a commit to python-social-auth/social-core that referenced this issue Jan 6, 2025
* Switch to pyproject.toml for project metadata

- import the metadata using pdm import
- use importlib metadata for in-code version display

* Install the dev dependencies with tox's own mechanism

* Fix the httpretty UnmockedError

This is due to gabrielfalcao/HTTPretty#484

* Remove flake8 configuration

Co-authored-by: Michal Čihař <[email protected]>
rebkwok added a commit to bennettoxford/bennettbot that referenced this issue Jan 9, 2025
httpretty has not been actively maintained for a while (there are a lot
of outstanding PRs and issues, and the last commit on main was 3 years
ago). We're already pinning it because of a bug, and it's now
incompatible with the latest version of urllib3
gabrielfalcao/HTTPretty#484

mocket does all the same things as httpretty and more (it does have a
plugin that aims to be a dropin replacement for httpretty, but it
doesn't cover all the ways that we use it). In any case, replacing our
use of httpretty with mocket is quite straightforward.
rebkwok added a commit to bennettoxford/bennettbot that referenced this issue Jan 9, 2025
httpretty has not been actively maintained for a while (there are a lot
of outstanding PRs and issues, and the last commit on main was 3 years
ago). We're already pinning it because of a bug, and it's now
incompatible with the latest version of urllib3
gabrielfalcao/HTTPretty#484

mocket does all the same things as httpretty and more (it does have a
plugin that aims to be a dropin replacement for httpretty, but it
doesn't cover all the ways that we use it). In any case, replacing our
use of httpretty with mocket is quite straightforward.
rebkwok added a commit to bennettoxford/bennettbot that referenced this issue Jan 10, 2025
httpretty has not been actively maintained for a while (there are a lot
of outstanding PRs and issues, and the last commit on main was 3 years
ago). We're already pinning it because of a bug, and it's now
incompatible with the latest version of urllib3
gabrielfalcao/HTTPretty#484

mocket does all the same things as httpretty and more (it does have a
plugin that aims to be a dropin replacement for httpretty, but it
doesn't cover all the ways that we use it). In any case, replacing our
use of httpretty with mocket is quite straightforward.
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

No branches or pull requests

1 participant