Problems to authenticate with Onedrive

Hello!

I’m developing an application in which I need to upload video-recorded files to Microsoft One Drive.

At the moment, the recording is not an issue. The issue is to authenticate with One Drive Servers using Auth 2.0.

I’m using python, and have been following these guides:

I can get the “code” variable, but when I set it inside a .env file and spin a balena push, I get the following error:

Traceback (most recent call last):
 main    File "/usr/src/app/demo.py", line 21, in <module>
 main      client.auth_provider.authenticate(code, redirect_uri, client_secret)
 main    File "/usr/local/lib/python3.5/dist-packages/onedrivesdk/auth_provider.py", line 203, in authenticate
 main      data=params)
 main    File "/usr/local/lib/python3.5/dist-packages/onedrivesdk/http_provider.py", line 71, in send
 main      custom_response = HttpResponse(response.status_code, response.headers, response.text)
 main    File "/usr/local/lib/python3.5/dist-packages/onedrivesdk/http_response.py", line 61, in __init__
 main      raise Exception(str(message["error"]))
 main  Exception: invalid_request


Traceback (most recent call last):
 main    File "/usr/src/app/demo.py", line 21, in <module>
 main      client.auth_provider.authenticate(code, redirect_uri, client_secret)
 main    File "/usr/local/lib/python3.5/dist-packages/onedrivesdk/auth_provider.py", line 203, in authenticate
 main      data=params)
 main    File "/usr/local/lib/python3.5/dist-packages/onedrivesdk/http_provider.py", line 71, in send
 main      custom_response = HttpResponse(response.status_code, response.headers, response.text)
 main    File "/usr/local/lib/python3.5/dist-packages/onedrivesdk/http_response.py", line 61, in __init__
 main      raise Exception(str(message["error"]))
 main  Exception: invalid_grant

Searching and trying to understand the whole mechanism, apparently, I need to “save the session” somehow and load it every time I make a request to the servers. What I don’t understand yet is how I will do that. Maybe saving as a device variable? But it is possible to do that programmatically from inside the Raspberry Pi 3? Using balena-sdk?

I feel that I’m not doing it the right way with lots of workarounds…

What’s the recommended way for uploading a video to a Cloud service using balena?

Thank you!

Hello, I checked the guide you linked but I don’t understand what’s going wrong in your case. Can you push your code to a GitHub repo and give us a link to check it out if that’s possible. It might be a issue with OneDrive SDK only but can’t say for sure. Thanks

Thank you for the support, @vipulgupta2048 !

The code can be accessed here: GitHub - arthurborgesdev/vetlog-spy: Software to monitor using a camera the pets in a vet hospital environment

The auth.py is the script that I used to grab the code variable. The demo.py is the main one, that I think I should run after, but I’m not sure if it expires frequently.

Hey there!

I think the repo you shared is private?

Can you please make it public?

Hello again,

I was re-reading the thread, and if I understand correctly, your use case is being able to backup recorded video files to oneDrive?

Have you seen our duplicati block. If you are unfamiliar with balenaBlocks you can read more here.

Essentially a block provides a functional piece that you can drop in your application. Here the duplicati block provides an easy way to backup files. So perhaps you could save your files to a named volume and make sure duplicati has access to that, then set up a backup job according to the instructions in the readme.

I hope i’m not adding more confusion here. Let us know how it turns out :slight_smile:

Thanks
Rahul

Hello,
Let us know if that worked out for you and if you were able to resolve the issue you were facing. Thanks!