bigcommerce/bigcommerce-api-python

406 Not Acceptable ({"error":"Invalid format."}) during api.oauth_fetch_token call

Closed this issue · 11 comments

Expected behavior

api = bigcommerce.api.BigcommerceApi(
client_id=config['bigcommerce'].get('client_id'),
store_hash=context, access_token='')

token = api.oauth_fetch_token(
config['bigcommerce'].get('client_secret'), code, context, scope,
config['bigcommerce'].get('redirect_uri'))
print(token)

{'access_token': '', 'scope': '', 'user':, 'context': ''}

Actual behavior

Python 3.6.3
bigcommerce==0.18.0

api = bigcommerce.api.BigcommerceApi(
client_id=config['bigcommerce'].get('client_id'),
store_hash=context, access_token='')

token = api.oauth_fetch_token(
config['bigcommerce'].get('client_secret'), code, context, scope,
config['bigcommerce'].get('redirect_uri'))

bigcommerce.exception.ClientRequestException: 406 Not Acceptable @ https://login.bigcommerce.com/oauth2/token: b'{"error":"Invalid format."}'

Steps to reproduce behavior

Upgrade bigcommerce to 0.18.0 (from the bigcommerce==0.17.3)

pip install bigcommerce==0.18.0
running in powershell terminal

@surbas any thoughts on this? I think this might have been introduced as a result of your work.

Just because of the changeset between the two versions - 0.17.3 works fine, and 0.18.0 is broken. Majority of the commits between the two are yours :)

@bookernath I took a look at the blame for the oauth_fetch_token and fetch_token methods that are throwing the ClientRequestException. The code for either has not change in 3 to 4 years and hence has nothing to do with the iteradd work that I did. Since I was already here... I took a deeper dive It seems like this is your server throwing an error. My gut tells me from looking at these functions that fault lies either on the input or the server. The code in question is doing a simple POST with very little handling of the inputs as far as I can tell.

@surbas I narrowed the issue down to the changes to connection.py in this commit: a9d9ba0

I think it's related to some of the refactoring; the OAuth token POST request uses the same methods as other API requests, and a lot of the underpinnings of that (fetch_token --> post --> run_method) are touched by your changes here.

Still digging into it...

@bookernath What are the steps to reproduce the reported bug to narrow down issue? Happy to write test and fix.

@surbas thanks for the follow-up!

@bookernath i just tried to deploy to heroku and got the following error: This is using the button on your link.

Traceback (most recent call last):
File "", line 1, in
File "/app/app.py", line 4, in
from flask_sqlalchemy import SQLAlchemy
ModuleNotFoundError: No module named 'flask_sqlalchemy'

@surbas I've updated the requirements.txt and it works now. Nice catch!

@bookernath switched to local. I can hit /instructions.html. When you say "install the app" you talking about heroku (which i was assuming) or on big commerce?

@surbas I mean to attempt the app installation flow by installing the draft app in your BC control panel.

To do this, you'll need to follow the full set of instructions and have a draft app created in BC. The error only occurs when the app is being installed, which is when the OAuth token exchange happens.