Hi all, I am trying to retrieve a picture from a url and save it in the uploads folder and then reference the file in the auth_user table, however I am getting AttributeError (folder) and I'm not sure why.
def save_facebook_image(fbid): if auth.user: import urllib2, os, io from PIL import Image 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'] image_link = urllib2.urlopen(direct_url) image_file = io.BytesIO(image_link.read()) img = Image.open(image_file) img_name = 'auth_user.image.%s.jpg' % auth.user.id img.save(os.path.join(request.folder, 'uploads', img_name), 'jpeg', quality=23) user_record.update_record(image=img_name) Here is the traceback: 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" <https://geods001.pythonanywhere.com/admin/edit/safeshoot/controllers/default.py>, line 2426, 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" <https://geods001.pythonanywhere.com/admin/edit/safeshoot/controllers/default.py>, line 476, 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" <https://geods001.pythonanywhere.com/admin/edit/safeshoot/controllers/default.py>, line 7, in <lambda> auth.settings.login_onaccept = [lambda form: save_facebook_image(session.fbid)] File "/home/geods001/web2py/applications/app/models/functions.py" <https://geods001.pythonanywhere.com/admin/edit/safeshoot/models/functions.py>, line 43, in save_facebook_image img.save(os.path.join(request.folder, 'uploads', img_name), 'jpeg', quality=23) File "/usr/lib/python2.7/urllib2.py", line 229, in __getattr__ raise AttributeError, attr AttributeError: folder Thanks in advance for your help! -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.