Skip to content

Change in default data download handling breaks astroquery #10227

Closed
astropy/astroquery
#1711

Description

@bsipocz

The recent PR #9964 breaks astroquery. We see these two test failures (run python setup.py test -P utils -R to reproduce):

I suppose we might be be able to patch it around, but as it's to be released in LTS, too I rather see it as an affect-dev bug:

======================================================= FAILURES =======================================================
_______________________________________________ test_filecontainer_save ________________________________________________

patch_getreadablefileobj = None

    def test_filecontainer_save(patch_getreadablefileobj):
        ffile = commons.FileContainer(fitsfilepath, encoding='binary')
        temp_dir = tempfile.mkdtemp()
        empty_temp_file = temp_dir + os.sep + 'test_emptyfile.fits'
>       ffile.save_fits(empty_temp_file)

astroquery/utils/tests/test_utils.py:463: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astroquery/utils/commons.py:390: in save_fits
    self.get_fits()
astroquery/utils/commons.py:365: in get_fits
    filedata = self.get_string()
astroquery/utils/commons.py:424: in get_string
    with self._readable_object as f:
/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py:112: in __enter__
    return next(self.gen)
/usr/local/lib/python3.7/site-packages/astropy/utils/data.py:237: in get_readable_fileobj
    http_headers=http_headers)
/usr/local/lib/python3.7/site-packages/astropy/utils/data.py:1172: in download_file
    ftp_tls=ftp_tls)
/usr/local/lib/python3.7/site-packages/astropy/utils/data.py:999: in _download_file_from_source
    with urlopener.open(req, timeout=timeout) as remote:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <urllib.request.OpenerDirector object at 0x135ca8ad0>
fullurl = '/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-1ysei6gt/lib/python3.7/site-packages/astroquery/utils/tests/../../sdss/tests/data/emptyfile.fits'
data = None, timeout = 10.0

    def open(self, fullurl, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
        # accept a URL or a Request object
        if isinstance(fullurl, str):
            req = Request(fullurl, data)
        else:
            req = fullurl
            if data is not None:
                req.data = data
    
>       req.timeout = timeout
E       AttributeError: 'str' object has no attribute 'timeout'

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py:516: AttributeError
------------------------------------------------- Captured stdout call -------------------------------------------------
Monkeyed URLrequest
Monkeyed URLrequest
________________________________________________ test_filecontainer_get ________________________________________________

patch_getreadablefileobj = None

    def test_filecontainer_get(patch_getreadablefileobj):
        ffile = commons.FileContainer(fitsfilepath, encoding='binary')
>       ff = ffile.get_fits()

astroquery/utils/tests/test_utils.py:469: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astroquery/utils/commons.py:365: in get_fits
    filedata = self.get_string()
astroquery/utils/commons.py:424: in get_string
    with self._readable_object as f:
/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py:112: in __enter__
    return next(self.gen)
/usr/local/lib/python3.7/site-packages/astropy/utils/data.py:237: in get_readable_fileobj
    http_headers=http_headers)
/usr/local/lib/python3.7/site-packages/astropy/utils/data.py:1172: in download_file
    ftp_tls=ftp_tls)
/usr/local/lib/python3.7/site-packages/astropy/utils/data.py:999: in _download_file_from_source
    with urlopener.open(req, timeout=timeout) as remote:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <urllib.request.OpenerDirector object at 0x135e4afd0>
fullurl = '/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-1ysei6gt/lib/python3.7/site-packages/astroquery/utils/tests/../../sdss/tests/data/emptyfile.fits'
data = None, timeout = 10.0

    def open(self, fullurl, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
        # accept a URL or a Request object
        if isinstance(fullurl, str):
            req = Request(fullurl, data)
        else:
            req = fullurl
            if data is not None:
                req.data = data
    
>       req.timeout = timeout
E       AttributeError: 'str' object has no attribute 'timeout'

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py:516: AttributeError
------------------------------------------------- Captured stdout call -------------------------------------------------
Monkeyed URLrequest
Monkeyed URLrequest
============================================= 2 failed, 54 passed in 8.24s =============================================

cc @eteq @pllim

Activity

  1. added this to the v4.0.2 milestone on Apr 29, 2020
  2. pllim commented on Apr 29, 2020

    @pllim
    Member

    To clarify: On the astroquery monkeypatch, all the patching of urllib.request.urlopen needs to be modified accordingly.

  3. self-assigned this
    on Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions