Skip to content

KeyError: 'There are no stored username-password credentials for this company id.' #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TST-akimond opened this issue Mar 13, 2020 · 4 comments
Labels

Comments

@TST-akimond
Copy link

TST-akimond commented Mar 13, 2020

After verification, I get this error while trying to get company files.
KeyError: 'There are no stored username-password credentials for this company id.'

stored_values = mycache.get('myob_creds')
credentials = PartnerCredentials(**stored_values)

print("=================== Myob Verify =======================")
print(stored_values)

print("====================1==================")
myob = Myob(credentials)
print(credentials)
print("====================2==================")
company_files = myob.companyfiles.all()
print(company_files)
print("====================2==================")

if len(company_files) > 0:
    print("====================3==================")
    comp = company_files[0]
    print("====================4==================")
    customers = comp.contacts.all()
    print("========== customers ================")
    print(customers)
    return (jsonify(company_files=company_files,customers=customers), 201)

print("========== Companies ================")
print(company_files)

I got error at here:
customers = comp.contacts.all()

company_files returns this:
[CompanyFile:
banking
company
contacts
general_ledger
inventory
invoices
orders
purchase_bills
purchase_orders]

@jarekwg
Copy link
Member

jarekwg commented Mar 13, 2020

There are two sets of credentials that are needed to get into a company file:

  • user credentials for MYOB login (you provide these when redirected to MYOB)
  • companyfile credentials (without these, you'll only be able to view the company file metadata, but not what's inside)

I think you've skipped over the second credentials. After verification, you need to provide username & password for the company file. See this line from the readme: cred.authenticate_companyfile(<company_id>, <username>, <password>)

Please also take a quick look at #18 and #33, which may help clear up some confusion.

@TST-akimond
Copy link
Author

I added companyfile credentials after verification.

stored_values = mycache.get('myob_creds')
credentials = PartnerCredentials(**stored_values)
credentials.authenticate_companyfile("eb04087e-e429-4471-8e10-4bdcf18282f7", "my-username", "my-password")

and then I got this error at here:
customers = comp.contacts.all()

myob.exceptions.MyobExceptionUnknown: (<Response [500]>, 'Internal Server Error')

@jarekwg
Copy link
Member

jarekwg commented Mar 15, 2020

Eh, MYOB 500s are not fun to deal with.
Try to wrap it in a try-except block, and see if there is any additional information in the 500 response:

try
    customers = comp.contacts.all()
except Exception as e:
    print(e.response.json())

Most likely it'll just be "contact support", but worth checking.

In my experience, I've generally only seen 500s on massive company files, where the MYOB api falls over trying to comb through the data. Is your company file large? (eg. 5+ years of invoicing?)

You could also try hitting some endpoints that aren't expected to be as large (eg. comp.general_ledger.taxcode())
Or, at least slimming down the contacts call to comp.general_ledger.customer() or comp.general_ledger.employee().

Lemme know how you go. You can also ask myob support about it.

Cheers,

@jarekwg
Copy link
Member

jarekwg commented Apr 2, 2020

Stale, closing.

@jarekwg jarekwg closed this as completed Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants