Forums

Problem in using Dropbox API's inside Pythonanywhere server

Hi, I have developed a Web app, there is a communication between Dropbox and the App through Dropbox API's.

FYI, My url = http://sansoftaus.pythonanywhere.com url where I get the error = http://sansoftaus.pythonanywhere.com/Submitted_Code

On my local PC setup I find no problems, but on Pythonanywhere, I get the following error:-

Environment:

Request Method: GET Request URL: http://sansoftaus.pythonanywhere.com/Submitted_Code/

Django Version: 1.3.7 Python Version: 2.7.4 Installed Applications:

['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles']

Installed Middleware:

('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/sansoftaus/Remote_Software/Development/views.py" in Submitted_code
  38.     dropbox_request_token = dropbox_sess.obtain_request_token()
File "/usr/local/lib/python2.7/dist-packages/dropbox/session.py" in obtain_request_token
  181.         response = self.rest_client.POST(url, headers=headers, params=params, raw_response=True)
File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in POST
  260.         return cls.IMPL.POST(*n, **kw)
File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in POST
  207.                             post_params=params, headers=headers, raw_response=raw_response)
File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in request
  177.             raise RESTSocketError(host, e)

Exception Type: RESTSocketError at /Submitted_Code/
Exception Value: Error connecting to "api.dropbox.com": [Errno 111] Connection refused

Kindly help me in solving the above problem...

Thanks, San

edited by admin for formatting

We only allow outgoing access to a limited number of sites for Free accounts. I'm quite surprised that api.dropbox.com was not in the whitelist already, so I've added it. It may still not work depending on the underlying url library that the dropbox rest client uses, but at least we're not getting in the way anymore.

Thanks Glenn, I will give a try now and let you know the status !

San

Hi Glen,

I still get the same error, Also, the whitelist https://www.pythonanywhere.com/whitelist/ is not yet updated with api.dropbox.com

How long it may take to get reflected ?

Thanks, San

It's possible that even after the PA devs have updated the list, it takes a little time to propagate through the system. Hopefully one of them will be able to drop by and give you an indication of how long this is likely to take. If it's not working in 24 hours I would definitely add another comment to this thread.

The whitelist on the site always lags the real thing because we only update it when we upgrade PythonAnywhere software.

You're still getting the error because the dropbox library does not honour the environment proxy settings so it's trying to go directly to api.dropbox.com and we block that. This is a fairly common issue with many of the Python REST libraries. You should raise the issue with the library authors.

Thanks Glenn ! I will escalate this issue to Dropbox team.

Also, do you think google drive would work well with pythonanywhere if am not able to use Dropbox ??

Thanks, San

Well, the Google Drive REST APIs are public so you could always implement your own code which uses them directly if ncessary (although OAuth is a bit fiddly). It's hard to say whether Google's own Python bindings will obey the proxy settings - it's one of those things which is better just to try and see how it works out.

Hi Glen,

Following was the response from Dropbox team:-

It looks like api.dropbox.com still isn't being allowed... try this:

import requests
print requests.get('https://api.dropbox.com').text

You'll see an error response from Squid, which appears to be what PythonAnywhere uses to proxy outbound requests.

Thread for this conversation:- https://forums.dropbox.com/topic.php?id=103225&replies=11#post-558061

Thanks, Santhosh

Hi Santhosh,

Did you actually try doing what the Dropbox support people asked you to?

In any case, I did! I've added a post on the dropbox forum, here's the conclusion:

  • requests is broken for some types of HTTPS over a proxy. There is an outstanding issue
  • curl -v https://api.dropbox.com does work, so it's not the proxy's fault
  • presumably Dropbox is broken in a similar way to requests.

So, for now the only solution is to pay up and upgrade! Go on, it's only $5. And, we have a 30-day money-back guarantee, so if for whatever reason you're not happy, or you can't get it working even with a paid account, we'll happily refund you...

Thanks Harry, I will upgrade my Account and start using Dropbox !! I will post if I face any problems....

~San

A small query on the pay... If I register today ie on 24th July for 5Dollar / month plan, will I be able to get the service until 24th August ?

Or do I need to again make a payment on 1st of August, please let me know how it works !

Thanks, San

If you pay today you get until 24 August.

Hi I upgraded my account by paying 6 Dollars / month (VAT = 1 Dollar) But am still not able to use api.dropbox.com

Following is the error :-

Environment:

Request Method: GET Request URL: http://ulmastersproject.pythonanywhere.com/Submitted_Code/

Django Version: 1.3.7 Python Version: 2.7.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, callback_args, callback_kwargs) File "/home/ulmastersproject/Remote_Software_Development/Development/views.py" in Submitted_code 38. dropbox_request_token = dropbox_sess.obtain_request_token() File "/usr/local/lib/python2.7/dist-packages/dropbox/session.py" in obtain_request_token 181. response = self.rest_client.POST(url, headers=headers, params=params, raw_response=True) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in POST 260. return cls.IMPL.POST(n, **kw) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in POST 207. post_params=params, headers=headers, raw_response=raw_response) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in request 177. raise RESTSocketError(host, e)

Exception Type: RESTSocketError at /Submitted_Code/ Exception Value: Error connecting to "api.dropbox.com": [Errno 111] Connection refused

Please help me....

URL: http://ulmastersproject.pythonanywhere.com/Submitted_Code/

Thanks, San

Have you tried reloading your web app? It may be required to get the upgraded environment to take effect.

Oh yes, after reloading it is working fine !! Am happy now :) Wow Integrated DropBox !!

Thanks Cartroo

Hmm, perhaps we need to make that clearer -- after upgrading, it's only new processes that pick up the upgrade. Thanks for helping out, Cartroo :-)

Hi,

I find a strange behavior with Dropbox Authentication... After receiving the dropbox request token, am trying to upload a tar file through the following API:- dropbox_client.put_file()

Following is the Error I receive:- Environment:

Request Method: GET Request URL: http://ulmastersproject.pythonanywhere.com/Submitted_Code/Add_to_dropbox/

Django Version: 1.3.7 Python Version: 2.7.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, callback_args, callback_kwargs) File "/home/ulmastersproject/Remote_Software_Development/Development/views.py" in Add_to_dropbox 83. response = dropbox_client.put_file('/Remote_Software.tar', f, overwrite=True) File "/usr/local/lib/python2.7/dist-packages/dropbox/client.py" in put_file 354. return self.rest_client.PUT(url, file_obj, headers) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in PUT 265. return cls.IMPL.PUT(n, **kw) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in PUT 211. return self.request("PUT", url, body=body, headers=headers, raw_response=raw_response) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py" in request 183. raise ErrorResponse(r)

Exception Type: ErrorResponse at /Submitted_Code/Add_to_dropbox/ Exception Value: [401] u'Authentication failed'

I do not get such errors on my local system, but through Pythonanywhere I get this Error, Do u think still there is some problem with Dropbox Rest API's or Pythonanywhere is blocking something ??

Pls help me out...

Thanks, San

Also, following is a strange behavior, I get the same error even after I have a paid account from pythonanywhere:-

On bash shell:-

from dropbox import client, rest, session
APP_KEY = <hidden>
APP_SECRET = <hidden>
ACCESS_TYPE = 'app_folder'
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
request_token = sess.obtain_request_token()
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/dropbox/session.py", line 181, in obtain_request_token response = self.rest_client.POST(url, headers=headers, params=params, raw_response=True) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py", line 260, in POST return cls.IMPL.POST(n, *kw) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py", line 207, in POST post_params=params, headers=headers, raw_response=raw_response) File "/usr/local/lib/python2.7/dist-packages/dropbox/rest.py", line 177, in request raise RESTSocketError(host, e) dropbox.rest.RESTSocketError: Error connecting to "api.dropbox.com": [Errno 111] Connection refused

The above commands on my local system works very well... Pls help me, I guess there is still some block from pythonanywhere to Dropbox (with Paid account)

Thanks, San

Pls help me, make me pass my University degree... This project decides my future ! I have paid as per your suggestion... Kindly help me out...

Thanks, San

We're not blocking anything. When you upgraded, we removed any filtering between the internet and your account. I see that you only have one console and the it was created before you upgraded. You need to start a new console to have the new paying settings applied to it.

EDIT: I started drafting this response before @Glenn's appeared, but I'll leave it intact despite the slight overlap.

Was that a newly-created bash shell? It wasn't one that you started before your account was upgraded was it? If so, you'll need to close it (easiest is to hit CTRL-D at the bash prompt) and then open a new one - this is for the same reason that your web app needed reloading.

The earlier problem with a 401 error looks different. I'm not familiar with the Dropbox API but this page seems to state that it means:

Bad or expired token. This can happen if the user or Dropbox revoked or expired an access token. To fix, you should re-authenticate the user.

Sounds to me like perhaps there's a bug in your OAuth code? For reference I've successfully authenticated like this:

session = dropbox.session.DropboxSession(APP_KEY, APP_SECRET, "dropbox")
request_token = session.obtain_request_token()
auth_url = session.build_authorize_url(request_token)
print "Visit " + auth_url + " and authorize app"
raw_input("Press ENTER when authorized")
access_token = session.obtain_access_token()

print "Access key: " + access_token.key
print "Access secret: " + access_token.secret

You then need to note down the key and secret in a file or database somewhere. You only need to do this once when the user first authorizes your app to your Dropbox account. After this point, assuming you've got the key and secret from earlier stored in ACCESS_KEY and ACCESS_SECRET then you can simply do something like this:

session = dropbox.session.DropboxSession(APP_KEY, APP_SECRET, "dropbox")
session.set_token(ACCESS_KEY, ACCESS_SECRET)
client = dropbox.client.DropboxClient(session)
account_info = client.account_info()
print "Hello, " + account_info["display_name"]

This code is, of course, just an example. But I've just retried it and it definitely works, so hopefully you can start from here.

Hi Glen,

Thanks, I was worried too much due to my project deadline... Yes, its working absolutely fine ! I love Pythonanywhere !!

Thanks again, San

Hi Cartroo,

Yes, that was a token error which I had messed up in my code, thanks again for your explanation.

~San