rozzac90 / matchbook

Python wrapper for Matchbook API
MIT License
15 stars 10 forks source link

Authorisation error #6

Closed xgshark closed 5 years ago

xgshark commented 6 years ago

from matchbook.apiclient import APIClient api = APIClient('username', 'password')

"api.market_data" and "api.reference_data" work fine like this.

I get "matchbook.exceptions.ApiError: ['You are not authorised to access this resource. Login to continue.']" for these endpoints: reporting, account, betting.

Why is that?

rozzac90 commented 6 years ago

have you got access to the api from matchbook? are you using you actual username and pw when creating the api instance? after the code above you may need to do api.login() in order to access any açcount specific information.

xgshark commented 6 years ago

Yeah I emailed matchbook support asking if I need special authorization before asking here. The reference and market data endpoints work without any user name and password - which I didn't know.

I've been trying loads of workarounds but don't get anything to work using the wrapper. api.session_token is None after making an instance so I assume login() needs to be called. I do however get an error when doing that.

user = "X" password = "X"

api = APIClient(user, password) api.login()

File ....py", line 22, in api.login() File ".../matchbook/endpoints/login.py", line 9, in call response = self.request("POST", self.client.urn_main, 'security/session', data=self.data, session=session) File ".../matchbook/endpoints/baseendpoint.py", line 31, in request check_status_code(response) File ".../matchbook/utils.py", line 61, in check_status_code raise ApiError(response) matchbook.exceptions.ApiError: ['Authentication Required']

This piece of code works so it shouldn't have anything to do with my account or credentials:

import json import requests

url = "https://www.matchbook.com/bpapi/rest/security/session" user = "X" password = "X"

payload = "{\n \"username\":\"" + user + "\",\n \"password\":\"" + password + "\"\n}" headers = {'content-type': "application/json"}

response = requests.request("POST", url, data=payload, headers=headers) json_data = json.loads(response.text) session_token = json_data["session-token"]

print(session_token)

url = "https://api.matchbook.com/edge/rest/account"

payload = {} headers = {'content-type': "application/json", 'session-token': session_token}

response = requests.request("GET", url, data=payload, headers=headers)

print("Account", response.text)

Thanks again for any help.

rozzac90 commented 6 years ago

I got a chance to try this on my laptop now. I get the following status 500 response from the login endpoint:

'{"errors":[{"messages":["Unexpected server error accessing /bpapi/rest/security/session."]}]}'

I'm not sure what is causing this but have emailed to see if its on their side that the issue is occuring.

Will let you know when they get back to me.

rozzac90 commented 6 years ago

Hi,

So it looks like it was just an issue with not having www. in the base url for login. I have fixed this and pushed version 0.0.5 to pypi so if you pip install -U matchbook to get this version it should be working now.

Let me know if this works for you and I will close the issue

xgshark commented 6 years ago

Fixed it, thanks!