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

Attempt to Download freeimage failing #111

Closed
virtualbrown opened this issue Dec 31, 2014 · 14 comments
Closed

Attempt to Download freeimage failing #111

virtualbrown opened this issue Dec 31, 2014 · 14 comments

Comments

@virtualbrown
Copy link

Installed Moviepy on Mac.
Try to run the first time and the download of free image is failing.

Exception Type: IOError at /
Exception Value: Error while fetching file https://github.com/imageio/imageio-binaries/raw/master/freeimage/libfreeimage-3.16.0-osx10.6.dylib.
Dataset fetching aborted (init() got an unexpected keyword argument 'context')

@Zulko
Copy link
Owner

Zulko commented Dec 31, 2014

Damn. Have you tried a second and third time just to be sure it wasn't a connexion problem (the error looks like a more serious issue but we never know).

@almarklein, any idea ?

@Zulko
Copy link
Owner

Zulko commented Dec 31, 2014

Also can you give your Python version ?

@almarklein
Copy link

The Dataset fetching aborted (__init__() got an unexpected keyword argument 'context') is surprising, because it seems to originate from elsewhere (urllib?)

@virtualbrown
Copy link
Author

Below is the full trace.

It seems to be bombing out in

File "/usr/local/lib/python2.7/site-packages/imageio/core/fetching.py" in _fetch_file

  1.                   'Dataset fetching aborted (%s)' % (url, e))
    

I've tried this several times with no luck. Also I manually downloaded the requested file and that works fine.

Any chance there is a workaround here where I can manually install freeimage? :)

Thx!


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.7
Python Version: 2.7.9
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'rest_framework',
'home',
'user',
'api',
'utils',
'contactus',
'common',
'stream')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response

  1.             resolver_match = resolver.resolve(request.path_info)
    
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in resolve
  2.         for pattern in self.url_patterns:
    
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  3.     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  4.         self._urlconf_module = import_module(self.urlconf_name)
    
    File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py" in import_module
  5. **import**(name)
    
    File "/Users/Mike/Projects/BandPass/Software/BandPass_Public/BandPass_Public/urls.py" in
  6. url(r'^api/', include('api.urls')),
    
    File "/Library/Python/2.7/site-packages/django/conf/urls/init.py" in include
  7.     urlconf_module = import_module(urlconf_module)
    
    File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py" in import_module
  8. **import**(name)
    
    File "/Users/Mike/Projects/BandPass/Software/BandPass_Public/api/urls.py" in
  9. from api.views import mediaitems
    File "/Users/Mike/Projects/BandPass/Software/BandPass_Public/api/views/mediaitems.py" in
  10. from moviepy.video.io import VideoFileClip
    File "/usr/local/lib/python2.7/site-packages/moviepy/video/io/VideoFileClip.py" in
  11. from moviepy.video.VideoClip import VideoClip
    File "/usr/local/lib/python2.7/site-packages/moviepy/video/VideoClip.py" in
  12. from .io.gif_writers import (write_gif,
    File "/usr/local/lib/python2.7/site-packages/moviepy/video/io/gif_writers.py" in
  13. import imageio
    File "/usr/local/lib/python2.7/site-packages/imageio/init.py" in
  14. from . import plugins # noqa
    File "/usr/local/lib/python2.7/site-packages/imageio/plugins/init.py" in
  15. from . import freeimage # noqa
    File "/usr/local/lib/python2.7/site-packages/imageio/plugins/freeimage.py" in
  16. from ._freeimage import fi, IO_FLAGS
    File "/usr/local/lib/python2.7/site-packages/imageio/plugins/_freeimage.py" in
  17. fi = Freeimage()
    
    File "/usr/local/lib/python2.7/site-packages/imageio/plugins/_freeimage.py" in init
  18.     self._load_freeimage()  
    
    File "/usr/local/lib/python2.7/site-packages/imageio/plugins/_freeimage.py" in _load_freeimage
  19.     lib_filename = get_freeimage_lib() or 'notavalidlibname'
    
    File "/usr/local/lib/python2.7/site-packages/imageio/plugins/_freeimage.py" in get_freeimage_lib
  20.         return get_remote_file('freeimage/' + LIBRARIES[plat])
    
    File "/usr/local/lib/python2.7/site-packages/imageio/core/fetching.py" in get_remote_file
  21.     _fetch_file(url, fname)
    
    File "/usr/local/lib/python2.7/site-packages/imageio/core/fetching.py" in _fetch_file
  22.                   'Dataset fetching aborted (%s)' % (url, e))
    

Exception Type: IOError at /
Exception Value: Error while fetching file https://github.com/imageio/imageio-binaries/raw/master/freeimage/libfreeimage-3.16.0-osx10.6.dylib.
Dataset fetching aborted (init() got an unexpected keyword argument 'context')

@almarklein
Copy link

Interesting. That last line in fetching.py actually catches an error and reraises it. I would very much like to know the original source. Can you try commenting the lines in imageio/core/fetching.py where the catching is done (in _fetch_file)? Or maybe find out the real source via debugging?

@virtualbrown
Copy link
Author

Sorry just now getting back to this. I traced this down in to urllb2.py.

class HTTPHandler(AbstractHTTPHandler):

def http_open(self, req):
    return self.do_open(httplib.HTTPConnection, req)

http_request = AbstractHTTPHandler.do_request_

if hasattr(httplib, 'HTTPS'):
class HTTPSHandler(AbstractHTTPHandler):

    def __init__(self, debuglevel=0, context=None):
        AbstractHTTPHandler.__init__(self, debuglevel)
        self._context = context

    def https_open(self, req):
        return self.do_open(httplib.HTTPSConnection, req,
            context=self._context)    <---- this is failing.  _context is None.  See do_open below.

def do_open(self, http_class, req, **http_conn_args):
"""Return an addinfourl object for the request, using http_class.

    http_class must implement the HTTPConnection API from httplib.
    The addinfourl return value is a file-like object.  It also
    has methods and attributes including:
        - info(): return a mimetools.Message object for the headers
        - geturl(): return the original request URL
        - code: HTTP status code
    """
    host = req.get_host()
    if not host:
        raise URLError('no host given')

    # will parse host:port
    h = http_class(host, timeout=req.timeout, **http_conn_args)    <--- this is where the exception is thrown.

**http_conn_args is a dictionary containing

{'context': None}

LMK if you need more. I'm not familiar enough with urllib to really understand what is going on there.

@almarklein
Copy link

From a brief look, I think this may be related to certificates. Can you please try changing https:// into http:// (i.e. remove the "s") in:

_url_root = 'https://github.com/imageio/imageio-binaries/raw/master/'

in fetching.py (line 47 in master).

@virtualbrown
Copy link
Author

Hi.

I made the change but still get the same error.

Exception Type: IOError at /
Exception Value: Error while fetching file http://github.com/imageio/imageio-binaries/raw/master/freeimage/libfreeimage-3.16.0-osx10.6.dylib.
Dataset fetching aborted (init() got an unexpected keyword argument 'context')

@virtualbrown
Copy link
Author

I made the following change in urllib2.py line 1166 and it worked.
At least this got the library to install.

def do_open(self, http_class, req, **http_conn_args):
"""Return an addinfourl object for the request, using http_class.

    http_class must implement the HTTPConnection API from httplib.
    The addinfourl return value is a file-like object.  It also
    has methods and attributes including:
        - info(): return a mimetools.Message object for the headers
        - geturl(): return the original request URL
        - code: HTTP status code
    """
    host = req.get_host()
    if not host:
        raise URLError('no host given')

    # will parse host:port
    #h = http_class(host, timeout=req.timeout, **http_conn_args)    <--- commented this out.
    h = http_class(host, timeout=req.timeout)

@almarklein
Copy link

Changing your urllib2.py file is not a very nice solution; it might break other code. Are you sure the http thing did not work? Because if you look at the code for http_open vs https_open you see the http version omits the context argument, which seems to be triggering the problem.

To be absolutely sure could you try just calling:

path = 'imageio/imageio-binaries/raw/master/freeimage/libfreeimage-3.16.0-osx10.6.dylib'
urlopen('https://github.com/' + path)  # should fail
urlopen('http://github.com/' + path)  # I hope this works

@virtualbrown
Copy link
Author

I tried that code and the http call fails as well with the following error.

init() got an unexpected keyword argument 'context' (<type 'exceptions.TypeError'>)

I'm pretty new to Python is it possible that I have incompatible libraries (based on version) somehow?

Also, regarding my tweak of urllib2, after I was able to download the file...I changed it back. I just needed a way to get around the download.

@almarklein
Copy link

I am not sure about the cause. It seems rather specific to your system. I was hoping we could find a way to change imageio to avoid the error, but it seems this is not possible.

I am glad you solved your problem. Let's hope your case was a rare exception.

@Zulko
Copy link
Owner

Zulko commented Jan 17, 2015

I'm leaving the issue open just in case someone else has the same problem.

@keikoro
Copy link
Collaborator

keikoro commented Feb 18, 2017

I'm closing this issue as it sounds like OP solved their problem and 2+ years later, no-one else has commented to have run into the same problem.

@keikoro keikoro closed this as completed Feb 18, 2017
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

4 participants