Closed ashish453 closed 4 years ago
Try rebooting your computer, and running your code as administrator/root/super user.
Well I can't. I am using Google Colab. My notebook on google colab is runing on 64 bit, 12 GB ram and python 3.6. That all what i know.
@ashish453 You won't be able to do that, then. Even if this worked, you'd need to be able to type things into a web browser that popped up on the Google Colab computer. This was meant to work on machines with an accessible desktop GUI, but a Google Colab computer is basically a command prompt that can run your code. Consider closing, as this is not related to onedrive-sdk-python
but more related to Google Colab.
If you continue running into this error on a computer that you can access, then delete your app on Azure and make it use the redirect URI http://localhost:9740
instead. Change your code to use that address too.
so isn't there any way to upload files in onedrive business from google colab?
@ashish453 use the other code sample instead:
import onedrivesdk
redirect_uri = 'http://localhost:8080/'
client_secret = 'your_client_secret'
client_id='your_client_id'
discovery_uri = 'api.office.com/discovery'
auth_server_url = 'login.microsoftonline.com/common/oauth2/authorize'
auth_token_url = 'login.microsoftonline.com/common/oauth2/token'
http_provider = onedrivesdk.HttpProvider()
auth_provider = onedrivesdk.AuthProvider(
http_provider=http_provider,
client_id=client_id,
auth_server_url=auth_server_url,
auth_token_url=auth_token_url)
client = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider)
auth_url = client.auth_provider.get_auth_url(redirect_uri)
# Ask for the code
print('Paste this URL into your browser, approve the app\'s access.')
print('Copy everything in the address bar after "code=", and paste it below.')
print(auth_url)
code = input('Paste code here: ')
client.auth_provider.authenticate(code, redirect_uri, client_secret, resource=discovery_uri)
The above code requires copy-pasting into your browser and back into your console. If you want to remove some of that manual work, you can use the helper class GetAuthCodeServer. That helper class spins up a webserver, so this method cannot be used on all environments. I didn't get this instruction. can you please explain me what to do before and after running the code..
@ashish453 it will generate a URL that you open in another tab. It gives you some stuff, and you copy and paste it back in.
@ashish453 why don't you just run it on your own computer?
Well I am using Google colab to download the large files from internet. As it gets downloaded very fast and then i need to upload it in onedrive. Using my PC it will consume terrible amount of time as i didn't have server as fast as google has to download 80 gb of files daily.
@ashish453 do it on your own computer, save your session to a pickle, and upload the pickle file and use it instead.
I can't log in into my account via the url generated by the code. When I enter my email It says That Microsoft account doesn't exist. Enter a different account or get a new one. But I do have onedrive account with my email.
@ashish453 try it again. If it still doesn't work see if you can log into online onedrive with the same email and password.
Yes i did. I can login by onedrive official page but i can't access my account from code generated link.
I have Onedrive For Business.
Try
import onedrivesdk
from onedrivesdk.helpers import GetAuthCodeServer
from onedrivesdk.helpers.resource_discovery import ResourceDiscoveryRequest
redirect_uri = 'http://localhost:8080'
client_id = "my client id"
client_secret = "my client secret"
discovery_uri = 'api.office.com/discovery'
auth_server_url = 'login.microsoftonline.com/common/oauth2/authorize'
auth_token_url = 'login.microsoftonline.com/common/oauth2/token'
http = onedrivesdk.HttpProvider()
auth = onedrivesdk.AuthProvider(http, client_id,
auth_server_url=auth_server_url,
auth_token_url=auth_token_url)
auth_url = auth.get_auth_url(redirect_uri)
print("Paste this in, and copy/paste the thing after 'code='.")
print(auth_url)
code = input('Paste code here: ')
auth.authenticate(code, redirect_uri, client_secret, resource=discovery_uri)
That is success, @ashish453! Copy the address. Run this code and paste in the address:
print(input("Paste the address and press enter: ").replace("http://localhost:8080/?code=", ""))
Copy what it outputs, and put it into the first code. I'll walk you through the next part. Let me know when you're ready.
@KTibow! In this line I did some changes:
auth_server_url = 'login.microsoftonline.com/common/oauth2/authorize'
auth_token_url = 'login.microsoftonline.com/common/oauth2/token
As compiler suggested:
MissingSchema: Invalid URL 'login.microsoftonline.com/common/oauth2/token': No schema supplied. Perhaps you meant http://login.microsoftonline.com/common/oauth2/token?
But when I do Run this :
import onedrivesdk
from onedrivesdk.helpers import GetAuthCodeServer
from onedrivesdk.helpers.resource_discovery import ResourceDiscoveryRequest
redirect_uri = 'http://localhost:8080'
client_id = "**********"
client_secret = "************"
discovery_uri = 'api.office.com/discovery'
auth_server_url = 'login.microsoftonline.com/common/oauth2/authorize'
auth_token_url = 'http://login.microsoftonline.com/common/oauth2/token?'
http = onedrivesdk.HttpProvider()
auth = onedrivesdk.AuthProvider(http, client_id,
auth_server_url=auth_server_url,
auth_token_url=auth_token_url)
auth_url = auth.get_auth_url(redirect_uri)
print("Paste this in, and copy/paste the thing after 'code='.")
print(auth_url)
code = input('Paste code here: ')
auth.authenticate(code, redirect_uri, client_secret, resource=discovery_uri)
Paste this in, and copy/paste the thing after 'code='.
login.microsoftonline.com/common/oauth2/authorize?client_id=4dca28ce-c82a-42d6-8690-f892663999d7&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080
Paste code here:
And paste the url in the code:
print(input("Paste the address and press enter: ").replace("http://localhost:8080/?code=", ""))
And I do get a code which i paste in above code.
I got this error:
Paste this in, and copy/paste the thing after 'code='.
login.microsoftonline.com/common/oauth2/authorize?client_id=4dca28ce-c82a-42d6-8690-f892663999d7&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080
Paste code here: ---------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-12-4303e874c9a5> in <module>()
18 print(auth_url)
19 code = input('Paste code here: ')
---> 20 auth.authenticate(code, redirect_uri, client_secret, resource=discovery_uri)
3 frames
/usr/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 3 column 1 (char 4)
What can I do now?
@KTibow I'm waiting for your reply.
@ashish453 I don't know what this is. I lost internet, so I couldn't see that you said that. Please edit your code out; it lets anyone have access to your account. You'll also need to delete the previous iteration. As for that, remove &session_state=e093b529-c981-4e01-b095-8db161662c73
so you just have the code:
The code has been removed for your safety
@ashish453 Please confirm that you've gotten the code.
@ashish453 I am deleting this today. Please confirm you have the code.
@ashish453 @Ashish45351 in 1 hour, I am removing the code.
@KTibow This doesn't work. I am still gting the same error again after removing &sesi............. By the I do find an alternative for my task. I found Mover.io by Microsoft did the same work without any code. And That was extermely fast.
But I still want Onedrive-sdk to do this work.
@ashish453 your code has expired. Please start from the beginning.
@KTibow I had started from very much beginning. Still same error. It worked for OneDrive personal but it's not working for OneDrive business.
@ashish453 Try using the same code but with onedrivesdk_fork. You'll need to change everywhere it says onedrivesdk
in the code to onedrivesdk_fork
.
By the way, we can still see the code if you look at the edit history. You need to delete that revision.
@KTibow This is giving me same error. please help bro.
### I decided to make a change:
auth_server_url = 'login.microsoftonline.com/common/oauth2/authorize'
auth_token_url = 'http://login.microsoftonline.com/common/oauth2/token?'
auth_server_url = 'https://login.microsoftonline.com/common/oauth2/authorize'
auth_token_url = 'https://login.microsoftonline.com/common/oauth2/token?'
### and now i get some different error:
Paste this in, and copy/paste the thing after 'code='.
https://login.microsoftonline.com/common/oauth2/authorize?client_id=8186bbd3-5cdc-41ca-8f4a-707f86b8cebd&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080
Paste code here: ********Zmx2kDH_KdCAA
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-19-1efc20771e9d> in <module>()
18 print(auth_url)
19 code = input('Paste code here: ')
---> 20 auth.authenticate(code, redirect_uri, client_secret, resource=discovery_uri)
2 frames
/usr/local/lib/python3.6/dist-packages/onedrivesdk_fork/http_response.py in __init__(self, status, headers, content)
59 raise OneDriveError(message["error"], self.status)
60 else:
---> 61 raise Exception(str(message["error"]))
62
63 def __str__(self):
Exception: invalid_resource
Possibly related to #113
Sent from Outlook Mobilehttps://aka.ms/blhgte
From: ashish453 notifications@github.com Sent: Tuesday, May 12, 2020 8:10:34 PM To: OneDrive/onedrive-sdk-python onedrive-sdk-python@noreply.github.com Cc: kendell kendell.r@outlook.com; Mention mention@noreply.github.com Subject: Re: [OneDrive/onedrive-sdk-python] OSError: [Errno 98] Address already in use` (#180)
auth_server_url = 'login.microsoftonline.com/common/oauth2/authorize' auth_token_url = 'http://login.microsoftonline.com/common/oauth2/token?'
In above code i just made the http to https
auth_server_url = 'https://login.microsoftonline.com/common/oauth2/authorize' auth_token_url = 'https://login.microsoftonline.com/common/oauth2/token?'
Exception Traceback (most recent call last)
@KTibow So this error can,t be fixed :(
Well, I don't know how. Since you're using onedrivesdk_fork
though, try mentioning @earonesty
to see if he knows any better than me.
I am using Google Colab. I installed onedrive-sdk-python by doing:
And this is my authentication code:
And I got this error:
Originally posted by @KTibow in https://github.com/OneDrive/onedrive-sdk-python/issues/179#issuecomment-624064609