box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
420 stars 215 forks source link

No "refresh_token" parameter found #618

Closed sad780 closed 3 years ago

sad780 commented 3 years ago

What am I doing wrong? Running the following script gives me an error:

oauth = boxsdk.OAuth2( client_id='xxx', client_secret='xxx', access_token='xxx', ) auth_url, csrf_token = oauth.get_authorization_url('https://usfs.app.box.com') client = boxsdk.Client(oauth)

items = client.folder(folder_id='0').get_items()

for item in items: print (item)


"GET https://api.box.com/2.0/folders/0/items?offset=0" 401 201 {'Date': 'Mon, 30 Aug 2021 18:23:38 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'x-envoy-upstream-service-time': '64', 'www-authenticate': 'Bearer realm="Service"', 'box-request-id': '0ff1c23d25aa7ef3747a79ff81da4f1be', 'cache-control': 'no-cache, no-store', 'strict-transport-security': 'max-age=31536000'} {'code': '---ized', 'help_url': 'http://developers.box.com/docs/#errors', 'message': 'Unauthorized - Cannot authorize with this service', 'request_id': 'dvk5ncgtzdhgmlin', 'status': 401, 'type': 'error'}  "POST https://api.box.com/oauth2/token" 400 86 {'Date': 'Mon, 30 Aug 2021 18:23:39 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=31536000', 'Set-Cookie': 'box_visitor_id=612d222ae3a2c1.62370555; expires=Tue, 30-Aug-2022 18:23:38 GMT; Max-Age=31536000; path=/; domain=.box.com; secure, bv=OPS-44671; expires=Mon, 06-Sep-2021 18:23:38 GMT; Max-Age=604800; path=/; domain=.app.box.com; secure, cn=69; expires=Tue, 30-Aug-2022 18:23:38 GMT; Max-Age=31536000; path=/; domain=.app.box.com; secure, site_preference=desktop; path=/; domain=.box.com; secure', 'Cache-Control': 'no-store'} {'error': 'invalid_request', 'error_description': 'No "refresh_token" parameter found'}  Traceback (most recent call last): File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\auth\oauth2.py", line 344, in _execute_token_request access_token=access_token, File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 158, in request response = self._prepare_and_send_request(method, url, **kwargs) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 406, in _prepare_and_send_request self._raise_on_unsuccessful_request(network_response, request) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 329, in _raise_on_unsuccessful_request network_response=network_response boxsdk.exception.BoxAPIException: Message: No "refresh_token" parameter found Status: 400 Code: invalid_request Request ID: None Headers: {'Date': 'Mon, 30 Aug 2021 18:23:39 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=31536000', 'Set-Cookie': 'box_visitor_id=612d222ae3a2c1.62370555; expires=Tue, 30-Aug-2022 18:23:38 GMT; Max-Age=31536000; path=/; domain=.box.com; secure, bv=OPS-44671; expires=Mon, 06-Sep-2021 18:23:38 GMT; Max-Age=604800; path=/; domain=.app.box.com; secure, cn=69; expires=Tue, 30-Aug-2022 18:23:38 GMT; Max-Age=31536000; path=/; domain=.app.box.com; secure, site_preference=desktop; path=/; domain=.box.com; secure', 'Cache-Control': 'no-store'} URL: https://api.box.com/oauth2/token Method: POST Context Info: None

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\sdelfavero\Box\R3 Aerial Photography\Tools\box.py", line 27, in for item in items: File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\pagination\box_object_collection.py", line 105, in next return next(self._all_items) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\pagination\box_object_collection.py", line 115, in _items_generator response_object = self._load_next_page() File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\pagination\box_object_collection.py", line 156, in _load_next_page box_response = self._session.get(self._url, params=params) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 102, in get return self.request('GET', url, kwargs) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 158, in request response = self._prepare_and_send_request(method, url, kwargs) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 397, in _prepare_and_send_request retry = self._get_retry_request_callable(network_response, attempt_number, request, **kwargs) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 590, in _get_retry_request_callable self._renew_session(network_response.access_token_used) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\session\session.py", line 560, in _renew_session new_accesstoken, = self._oauth.refresh(access_token_used) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\auth\oauth2.py", line 266, in refresh access_token, refresh_token = self._refresh(access_token_to_refresh) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\auth\oauth2.py", line 218, in _refresh return self.send_token_request(data, access_token) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\auth\oauth2.py", line 401, in send_token_request token_response = self._execute_token_request(data, access_token, expect_refresh_token) File "C:\Users\sdelfavero\AppData\Roaming\Python\Python37\site-packages\boxsdk\auth\oauth2.py", line 347, in _execute_token_request six.raise_from(self._oauth_exception(box_api_exception.network_response, url), box_api_exception) File "", line 3, in raise_from boxsdk.exception.BoxOAuthException: Message: No "refresh_token" parameter found Status: 400 URL: https://api.box.com/oauth2/token Method: POST Headers: {'Date': 'Mon, 30 Aug 2021 18:23:39 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=31536000', 'Set-Cookie': 'box_visitor_id=612d222ae3a2c1.62370555; expires=Tue, 30-Aug-2022 18:23:38 GMT; Max-Age=31536000; path=/; domain=.box.com; secure, bv=OPS-44671; expires=Mon, 06-Sep-2021 18:23:38 GMT; Max-Age=604800; path=/; domain=.app.box.com; secure, cn=69; expires=Tue, 30-Aug-2022 18:23:38 GMT; Max-Age=31536000; path=/; domain=.app.box.com; secure, site_preference=desktop; path=/; domain=.box.com; secure', 'Cache-Control': 'no-store'}

mwwoda commented 3 years ago

Hi @sad780

The root cause looks like it's related to the account settings (Unauthorized - Cannot authorize with this service). Please refer to our docs https://support.box.com/hc/en-us/articles/360044193313-API-Content-Unauthorized-Cannot-authorize-with-this-service-. If you want some help with the authorization itself, refer to our api docs and repo's readme.

Hope that helps! Feel free to reopen if this problem persists.

Thanks, @mwwoda