swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

Python: 'module' object has no attribute url #964

Closed EntilZha closed 9 years ago

EntilZha commented 9 years ago

I am writing some code which uses the generated code libraries and am running into a stack trace that looks like this (on develop_2.0, not using 2.1.3 since it doesn't include the patch for incorrect directory):

Traceback (most recent call last):
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/test_discovery_api.py", line 26, in test_offset
    response_0 = self.discovery_api.discovery_v1_photoboards_get()
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/apis/discovery_api.py", line 182, in discovery_v1_photoboards_get
    response='DiscoveryResponse', auth_settings=auth_settings)
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/api_client.py", line 101, in call_api
    post_params=post_params, body=body)
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/api_client.py", line 236, in request
    return RESTClient.GET(url, query_params=query_params, headers=headers)
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/rest.py", line 218, in GET
    return cls.IMPL.GET(*n, **kw)
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/rest.py", line 148, in GET
    return self.request("GET", url, headers=headers, query_params=query_params)
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/rest.py", line 123, in request
    r = self.agent(url).request(method, url,
  File "/Users/prodriguez/Code/datascience-api/docs-tests/tests/integration/datascience_api/rest.py", line 70, in agent
    url = urllib3.util.url.parse_url(url)
AttributeError: 'module' object has no attribute 'url'

Basically the problem is that the code has this call:

urllib3.util.url.parse_url

It should be:

urllib3.util.parse_url

On a different note, this and a couple other bugs I have found (like the incorrect directory name) point to that Python code generation seems second class and not well maintained. How trustworthy can I be of the code to be correct? I am using it in a production system so would like to get a feeling for that, and if it is not super well maintained, are there some low hanging fruit to help out with?

geekerzp commented 9 years ago

Hi @EntilZha I have tested urllib3.util.url.parse_url and urllib3.util.parse_url in ipython of python v2 and python v3, and both methods work fine.

>>> urllib3.util.url.parse_url("http://www.google.com")
Url(scheme='http', auth=None, host='www.google.com', port=None, path=None, query=None, fragment=None)

>>> urllib3.util.parse_url("http://www.google.com")
Url(scheme='http', auth=None, host='www.google.com', port=None, path=None, query=None, fragment=None)

In fact, they are the same method as they have the same memory address:

>>> urllib3.util.url.parse_url
<function parse_url at 0x1057301e0>

>>> urllib3.util.parse_url
<function parse_url at 0x1057301e0>

You also can look into the source code of urllib3: https://github.com/shazow/urllib3/blob/master/urllib3/util/url.py#L121 https://github.com/shazow/urllib3/blob/master/urllib3/util/__init__.py#L21

EntilZha commented 9 years ago

What might explain the error? I was using this within a docker environment so the installations are from latest pypi release. My guess is that somewhere I have a version discrepancy.

EntilZha commented 9 years ago

I think I know what happened. When I ran tests locally, it was using my older 1.7.1 version of urllib3 on my local machine. On docker it was using a newer version, but by the time I ran the tests there, I already had changed the call to urllib3.util.parse_url so didn't see that either would work in the newest version.

My proposal would be to keep urllib3.util.parse_url since it is better for backwards compatibility (seems like the url package was added to organize repo), but in any case my problem would be fixed by upgrading.

geekerzp commented 9 years ago

Thanks @EntilZha , I will change urllib3.util.url.parse_url to urllib3.util.parse_url for backwards compatibility, and would be better you can upgrade your urllib3.