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

Import urllib.request explicitly #227

Closed
csala opened this issue Oct 30, 2020 · 0 comments · Fixed by #231
Closed

Import urllib.request explicitly #227

csala opened this issue Oct 30, 2020 · 0 comments · Fixed by #231
Assignees
Labels
internal The issue doesn't change the API or functionality
Milestone

Comments

@csala
Copy link
Contributor

csala commented Oct 30, 2020

Inside sdv/demo.py there is a line that imports urllib, which later on is used to call urllib.request.
However, urllib does not have the attribute request unless it has been explicitly exported before by using either from urllib import request or import urllib.request statements.

Because of this, when functions from the sdv.demo sub-package are used before anything else, the code raises an AttributeError (see #224 (comment)).

In order to fix this, we should explicitly import urllib.request instead of just urllib.

See the usage examples in the urllib.request docs and this stackoverflow question for reference.

Steps to reproduce

Inside a fresh virtualenv, open a simple python prompt and try to run the sdv.demo.load_timeseries_demo function.

$ python
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sdv.demo import load_timeseries_demo
>>> data = load_timeseries_demo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xals/.virtualenvs/sdv-test/lib/python3.6/site-packages/sdv/demo.py", line 322, in load_timeseries_demo
    return load_tabular_demo(dataset_name, table_name, data_path=DATA_PATH, metadata=metadata)
  File "/home/xals/.virtualenvs/sdv-test/lib/python3.6/site-packages/sdv/demo.py", line 252, in load_tabular_demo
    meta, tables = _load_demo_dataset(dataset_name, data_path)
  File "/home/xals/.virtualenvs/sdv-test/lib/python3.6/site-packages/sdv/demo.py", line 158, in _load_demo_dataset
    dataset_path = _get_dataset_path(dataset_name, data_path)
  File "/home/xals/.virtualenvs/sdv-test/lib/python3.6/site-packages/sdv/demo.py", line 116, in _get_dataset_path
    _download(dataset_name, data_path)
  File "/home/xals/.virtualenvs/sdv-test/lib/python3.6/site-packages/sdv/demo.py", line 103, in _download
    response = urllib.request.urlopen(url)
AttributeError: module 'urllib' has no attribute 'request'

Temporary Workaround

In order to prevent the issue, one can simply import urllib.request explicitly before running the sdv.demo code:

$ python
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> from sdv.demo import load_timeseries_demo
>>> data = load_timeseries_demo()
>>> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal The issue doesn't change the API or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant