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: cannot pickle 'generator' object with urllib 2.1.0, no error with urllib 1.26.18 #814

Open
anton-daneyko-ultramarin opened this issue Jan 29, 2024 · 0 comments

Comments

@anton-daneyko-ultramarin

I get a TypeError: cannot pickle 'generator' object error when using urllib3 v2.1.0 and the error goes away with urllib3 v1.26.18. The vcrpy version is 5.1.0; Python v3.10.13.

The stack trace leads to before_record_request in vcr/config.py. I probably won't be able to provide a good reproducible example right now, but I thought it might be helpful to leave some breadcrumbs for a future investigation:

/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/site-packages/requests/adapters.py:486: in send
    resp = conn.urlopen(
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/site-packages/urllib3/connectionpool.py:790: in urlopen
    response = self._make_request(
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/site-packages/urllib3/connectionpool.py:536: in _make_request
    response = conn.getresponse()
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/site-packages/vcr/stubs/__init__.py:257: in getresponse
    if self.cassette.can_play_response_for(self._vcr_request):
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/site-packages/vcr/cassette.py:263: in can_play_response_for
    request = self._before_record_request(request)
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/site-packages/vcr/config.py:223: in before_record_request
    request = copy.deepcopy(request)
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/copy.py:172: in deepcopy
    y = _reconstruct(x, memo, *rv)
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/copy.py:271: in _reconstruct
    state = deepcopy(state, memo)
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/copy.py:146: in deepcopy
    y = copier(x, memo)
/home/acme-corp/.conda/envs/apa-proxy/lib/python3.10/copy.py:231: in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
x = <generator object Client.upload_data.<locals>.json_stream at 0x7f792ac86030>
memo = {140158380145104: <[AttributeError("'Request' object has no attribute 'method'") raised in repr()] Request object at 0...', 'uri': 'http://localhost:8080/websrv/portfolios/test_cancel_task/dates?enforce-partial-import=false'}}
_nil = []
    def deepcopy(x, memo=None, _nil=[]):
        """Deep copy operation on arbitrary Python objects.
    
        See the module's __doc__ string for more info.
        """
    
        if memo is None:
            memo = {}
    
        d = id(x)
        y = memo.get(d, _nil)
        if y is not _nil:
            return y
    
        cls = type(x)
    
        copier = _deepcopy_dispatch.get(cls)
        if copier is not None:
            y = copier(x, memo)
        else:
            if issubclass(cls, type):
                y = _deepcopy_atomic(x, memo)
            else:
                copier = getattr(x, "__deepcopy__", None)
                if copier is not None:
                    y = copier(memo)
                else:
                    reductor = dispatch_table.get(cls)
                    if reductor:
                        rv = reductor(x)
                    else:
                        reductor = getattr(x, "__reduce_ex__", None)
                        if reductor is not None:
>                           rv = reductor(4)
E                           TypeError: cannot pickle 'generator' object
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