omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    5
    2138
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • roosterboy
      roosterboy last edited by

      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?

      mikael 1 Reply Last reply Reply Quote 0
      • Robert_Tompkins
        Robert_Tompkins last edited by

        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 :p

        Use the </> button and paste the code producing those errors.

        1 Reply Last reply Reply Quote 0
        • mikael
          mikael @roosterboy last edited by

          @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:

          • Flow for OneDrive
          • Flow for Spotify

          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).

          1 Reply Last reply Reply Quote 0
          • roosterboy
            roosterboy last edited by roosterboy

            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 the try block of get_hints() and got a different error: Error opening hints file [401] 'Invalid signature.'

            mikael 1 Reply Last reply Reply Quote 0
            • mikael
              mikael @roosterboy last edited by

              @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?

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors