Project

Profile

Help

Issue #5623

OpenAPI generated client - Failed to parse in urllib3

Added by Timoses about 1 month ago. Updated about 1 month ago.

Status:
NEW
Priority:
Normal
Assignee:
-
Category:
API
Sprint/Milestone:
-
Start date:
Due date:
Severity:
2. Medium
Version:
Platform Release:
Blocks Release:
OS:
CentOS 7
Backwards Incompatible:
No
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
API Bindings, Documentation
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:

Description

pulpcore-client: latest (3.0.0rc8.dev1572012888)

The following triggers an error:

        from pulpcore.client.pulpcore.configuration import Configuration
        from pulpcore.client.pulpcore.api_client import ApiClient
        from pulpcore.client.pulpcore.api.repositories_api import RepositoriesApi
        config = Configuration(username='admin',  password='password')
        client = ApiClient(configuration=config)
        api = RepositoriesApi(client)
        api.read('/pulp/api/v3/repositories/4f94aa44-729f-445e-926f-5b1139aee291/')

  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/api/repositories_api.py\", line 521, in read
    return self.read_with_http_info(repository_href, **kwargs)  # noqa: E501
  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/api/repositories_api.py\", line 609, in read_with_http_info
    collection_formats=collection_formats)
  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/api_client.py\", line 346, in call_api
    _preload_content, _request_timeout, _host)
  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/api_client.py\", line 177, in __call_api
    _request_timeout=_request_timeout)
  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/api_client.py\", line 369, in request
    headers=headers)
  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/rest.py\", line 239, in GET
    query_params=query_params)
  File \"/usr/lib/python2.7/site-packages/pulpcore/client/pulpcore/rest.py\", line 212, in request
    headers=headers)
  File \"/usr/lib/python2.7/site-packages/urllib3/request.py\", line 76, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File \"/usr/lib/python2.7/site-packages/urllib3/request.py\", line 97, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File \"/usr/lib/python2.7/site-packages/urllib3/poolmanager.py\", line 318, in urlopen
    u = parse_url(url)
  File \"/usr/lib/python2.7/site-packages/urllib3/util/url.py\", line 401, in parse_url
    return six.raise_from(LocationParseError(source_url), None)
  File \"/usr/lib/python2.7/site-packages/urllib3/packages/six.py\", line 788, in raise_from
    raise value
urllib3.exceptions.LocationParseError: Failed to parse: http://localhost:24817%2Fpulp%2Fapi%2Fv3%2Frepositories%2F4f94aa44-729f-445e-926f-5b1139aee291%2F

Try it yourself:

git clone https://github.com/Timoses/pulp3
cd pulp3
git checkout 5f0b86e3
ansible-galaxy install -r requirements.yml -p roles
vagrant up

Triggering line: https://github.com/Timoses/pulp3/commit/5f0b86e3e3c5a99802e1a32e4269e9d74f4b11ff#diff-d893f4f9daec0843269e999b2a061754R97

History

#1 Updated by Timoses about 1 month ago

The error appears to be below (see commented mark):

pulpcore/client/pulpcore/api_client.py:

109     def __call_api(
110             self, resource_path, method, path_params=None,
111             query_params=None, header_params=None, body=None, post_params=None,
112             files=None, response_type=None, auth_settings=None,
113             _return_http_data_only=None, collection_formats=None,
114             _preload_content=True, _request_timeout=None, _host=None):
115
116         config = self.configuration
117
118         # header parameters
119         header_params = header_params or {}
120         header_params.update(self.default_headers)
121         if self.cookie:
122             header_params['Cookie'] = self.cookie
123         if header_params:
124             header_params = self.sanitize_for_serialization(header_params)
125             header_params = dict(self.parameters_to_tuples(header_params,
126                                                            collection_formats))
127
128         # path parameters
129         if path_params:
130             path_params = self.sanitize_for_serialization(path_params)
131             path_params = self.parameters_to_tuples(path_params,
132                                                     collection_formats)
133             for k, v in path_params:
134                 # specified safe chars, encode everything
135                 resource_path = resource_path.replace(
136                     '{%s}' % k
137                     quote(str(v), safe=config.safe_chars_for_path_param)        #   <<<<< -----  !!  HERE  !!  ----- Transformation of "/" to "%2F" 
138                 )

#2 Updated by Timoses about 1 month ago

Figured it out...

Turns out that

config.safe_chars_for_path_param = '/'

prevents quotation from happening in urllib.quote:

quote(str(v), safe=config.safe_chars_for_path_param) 

#3 Updated by dkliban@redhat.com about 1 month ago

This is a documentation bug. We should make it clear that specifying that config setting is required when using the client.

#4 Updated by fabricio.aguiar about 1 month ago

  • Triaged changed from No to Yes
  • Tags Documentation added

#5 Updated by bmbouter about 1 month ago

  • Sprint/Milestone deleted (3.0)

Please register to edit this issue

Also available in: Atom PDF