You cannot pass a URL to the open() function -- you must use something like urllib2 or the requests library to retrieve data from a URL.
Anthony On Monday, July 18, 2016 at 10:43:54 AM UTC-4, Daniel wrote: > > Hi guys thanks again for your help. So I am using a stream object as > outlined in the book, however its throwing 'no such file or directory'. But > when I go to the url there is a jpg file attached. I thought it could be > because the url does not end with the file extension, however I tried a > different url and the same error occurred. What am I doing wrong? > > > def save_facebook_image(fbid): > if auth.user: > user_record = db.auth_user(auth.user.id) > > url = "https://graph.facebook.com/"+ > str(fbid)+"/picture?type=large&redirect=false" > request = urllib2.Request (url) > the_response = urllib2.urlopen (request) > json_data = json.load(the_response) > direct_url = json_data['data']['url'] > > stream = open(direct_url, 'rb') > user_record.update_record(image=stream) > > Traceback > > > 2. > 3. > 4. > 5. > 6. > 7. > 8. > 9. > 10. > 11. > 12. > 13. > 14. > 15. > 16. > 17. > 18. > > Traceback (most recent call last): > File "/home/geods001/web2py/gluon/restricted.py", line 227, in restricted > exec ccode in environment > File "/home/geods001/web2py/applications/app/controllers/default.py", line > 2460, in <module> > File "/home/geods001/web2py/gluon/globals.py", line 412, in <lambda> > self._caller = lambda f: f() > File "/home/geods001/web2py/applications/app/controllers/default.py", line > 477, in user > form = auth.login() > File "/home/geods001/web2py/gluon/tools.py", line 2808, in login > callback(onaccept, None) > File "/home/geods001/web2py/gluon/tools.py", line 88, in callback > [action(form) for action in actions] > File "/home/geods001/web2py/applications/app/controllers/default.py", line > 474, in <lambda> > auth.settings.login_onaccept = [lambda form: > save_facebook_image(session.fbid)] > File "/home/geods001/web2py/applications/app/models/functions.py", line 28, > in save_facebook_image > stream = open(direct_url, 'rb') > IOError: [Errno 2] No such file or directory: > u'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/13775427_105852749854987_3865523947457072666_n.jpg?oh=d30faaee9346c4bc79b9a502e2dd9875&oe=57EA9A37' > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

