Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
dropbox login
-
I've been away from using Pythonista for a while but now have need to write a script that reads the contents of a text file in my Dropbox. I'm having a heck of a time getting this to work.
I've set up my app in the Dropbox settings, I've got my key and secret, I get through the authorization up until the point where I have to enter a code. I pasted the given code into the console but I get back Error: 400 Client Error: Bad Request for url: https://www.dropbox.com/1/oauth2/token and object of type 'NoneType' has no len()
Can anyone explain to me how to get this working?
-
I may or may not be able to help you. However, somebody can.
But I bet that somebody will ask to see what your code looks like :pUse the </> button and paste the code producing those errors.
-
@roosterboy, looks like you are trying to implement an oauth flow, which tend to be almost always the same.
Suggest comparing your code to these, or taking and versioning one of them:
Let me know if you get stuck, and I can take a moment to make a Dropbox version (or, more likely, generalize one of these to be configurable).
-
Sorry about not including any code.
I'm using this gist that has worked with another script for several years. In that script, I upload a plist file to dropbox. I use it a couple times a week and it works without a hitch.
But this new script, that downloads a text file, isn't working at all and gives me the errors mentioned in the first post. And, weirdly, the comments on that gist indicate the same errors for those users. Yet, this code has worked for me with my other script.
Here is my code that calls that gist dropbox login code:
import dropboxloginv2 as dropboxlogin import console from dropbox import rest dropboxlogin.app_key = '...' #with my app_key dropboxlogin.app_secret = '...' #with my app_secret DBX = dropboxlogin.get_client() AUTOTAG_PATH = '/github/scripts/python/autotag_hints.txt' def get_hints(): try: md, res = DBX.files_download(AUTOTAG_PATH) except rest.ErrorResponse as e: console.alert('Error opening hints file', message='{}\n'.format(e)) return None data = res.content for line in data: (ptn, tags) = line.split(' :: ') hints[ptn] = tags.split(' ') return hints def main(): autotag_hints = get_hints() print(autotag_hints) if __name__ == '__main__': main()
I tried moving the line
DBX = dropboxlogin.get_client()
inside thetry
block ofget_hints()
and got a different error: Error opening hints file [401] 'Invalid signature.' -
@roosterboy, ok, haven’t used the dropbox module, but if login works for something but does not work for something else, with oauth it is typically because the authorization is tied to a specific
scope
of allowed actions. I did not see the scope set in the code, is it set somewhere where you obtain the API key and secret?