Not able to retrieve Account Balance
Cesco85 opened this issue · 4 comments
Hi everyone, I am pretty new with plaid, and I have issues retrieving my Account Balance.
After having looked at the documentation in this repository, this is the code I am using:
import plaid
from plaid.api import plaid_api
from plaid.model.accounts_balance_get_request import AccountsBalanceGetRequest
configuration = plaid.Configuration(
host=plaid.Environment.Sandbox,
api_key={
'clientId': client_id,
'secret': secret,
'environment': environment,
}
)
api_client = plaid.ApiClient(configuration)
client = plaid_api.PlaidApi(api_client)
balance_request = AccountsBalanceGetRequest(
access_token=access_token,
)
balance_response = client.accounts_balance_get(balance_request)
However, at this stage I get this error message:
TypeError Traceback (most recent call last)
/usr/local/bin/kernel-launchers/python/scripts/launch_ipykernel.py in <module>
20 )
21
---> 22 balance_response = client.accounts_balance_get(balance_request)
~/.local/lib/python3.6/site-packages/plaid/api_client.py in __call__(self, *args, **kwargs)
767
768 """
--> 769 return self.callable(self, *args, **kwargs)
770
771 def call_with_http_info(self, **kwargs):
~/.local/lib/python3.6/site-packages/plaid/api/plaid_api.py in __accounts_balance_get(self, accounts_balance_get_request, **kwargs)
479 kwargs['accounts_balance_get_request'] = \
480 accounts_balance_get_request
--> 481 return self.call_with_http_info(**kwargs)
482
483 self.accounts_balance_get = _Endpoint(
~/.local/lib/python3.6/site-packages/plaid/api_client.py in call_with_http_info(self, **kwargs)
845 _request_timeout=kwargs['_request_timeout'],
846 _host=_host,
--> 847 collection_formats=params['collection_format'])
~/.local/lib/python3.6/site-packages/plaid/api_client.py in call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async_req, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)
410 _return_http_data_only, collection_formats,
411 _preload_content, _request_timeout, _host,
--> 412 _check_type)
413
414 return self.pool.apply_async(self.__call_api, (resource_path,
~/.local/lib/python3.6/site-packages/plaid/api_client.py in __call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)
195 post_params=post_params, body=body,
196 _preload_content=_preload_content,
--> 197 _request_timeout=_request_timeout)
198 except ApiException as e:
199 e.body = e.body.decode('utf-8')
~/.local/lib/python3.6/site-packages/plaid/api_client.py in request(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)
456 _preload_content=_preload_content,
457 _request_timeout=_request_timeout,
--> 458 body=body)
459 elif method == "PUT":
460 return self.rest_client.PUT(url,
~/.local/lib/python3.6/site-packages/plaid/rest.py in POST(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)
268 _preload_content=_preload_content,
269 _request_timeout=_request_timeout,
--> 270 body=body)
271
272 def PUT(self, url, headers=None, query_params=None, post_params=None,
~/.local/lib/python3.6/site-packages/plaid/rest.py in request(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)
153 preload_content=_preload_content,
154 timeout=timeout,
--> 155 headers=headers)
156 elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
157 r = self.pool_manager.request(
/usr/local/lib/python3.6/dist-packages/urllib3/request.py in request(self, method, url, fields, headers, **urlopen_kw)
77 else:
78 return self.request_encode_body(
---> 79 method, url, fields=fields, headers=headers, **urlopen_kw
80 )
81
/usr/local/lib/python3.6/dist-packages/urllib3/request.py in request_encode_body(self, method, url, fields, headers, encode_multipart, multipart_boundary, **urlopen_kw)
168 extra_kw.update(urlopen_kw)
169
--> 170 return self.urlopen(method, url, **extra_kw)
/usr/local/lib/python3.6/dist-packages/urllib3/poolmanager.py in urlopen(self, method, url, redirect, **kw)
373 response = conn.urlopen(method, url, **kw)
374 else:
--> 375 response = conn.urlopen(method, u.request_uri, **kw)
376
377 redirect_location = redirect and response.get_redirect_location()
/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
704 body=body,
705 headers=headers,
--> 706 chunked=chunked,
707 )
708
/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
392 conn.request_chunked(method, url, **httplib_request_kw)
393 else:
--> 394 conn.request(method, url, **httplib_request_kw)
395
396 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
/usr/local/lib/python3.6/dist-packages/urllib3/connection.py in request(self, method, url, body, headers)
232 if "user-agent" not in (six.ensure_str(k.lower()) for k in headers):
233 headers["User-Agent"] = _get_default_user_agent()
--> 234 super(HTTPConnection, self).request(method, url, body=body, headers=headers)
235
236 def request_chunked(self, method, url, body=None, headers=None):
/usr/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
1279 encode_chunked=False):
1280 """Send a complete request to the server."""
-> 1281 self._send_request(method, url, body, headers, encode_chunked)
1282
1283 def _send_request(self, method, url, body, headers, encode_chunked):
/usr/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1320
1321 for hdr, value in headers.items():
-> 1322 self.putheader(hdr, value)
1323 if isinstance(body, str):
1324 # RFC 2616 Section 3.7.1 says that text default has a
/usr/local/lib/python3.6/dist-packages/urllib3/connection.py in putheader(self, header, *values)
217 """"""
218 if SKIP_HEADER not in values:
--> 219 _HTTPConnection.putheader(self, header, *values)
220 elif six.ensure_str(header.lower()) not in SKIPPABLE_HEADERS:
221 raise ValueError(
/usr/lib/python3.6/http/client.py in putheader(self, header, *values)
1256 values[i] = str(one_value).encode('ascii')
1257
-> 1258 if _is_illegal_header_value(values[i]):
1259 raise ValueError('Invalid header value %r' % (values[i],))
1260
TypeError: expected string or bytes-like object
The problem is, I have the suspicious this is due to either the access_token or the secret not being valid any more.
Could you please tell me if otherwise there is a mistake in my code? Thank you very much
Compare your object to the sample configuration object in the readme:
configuration = plaid.Configuration(
host=plaid.Environment.Sandbox,
api_key={
'clientId': client_id,
'secret': secret,
}
)
It doesn't appear to be constructed in the same way.
If you are having trouble constructing the object I'd recommend beginning with the quickstart code at https://github.com/plaid/quickstart which should give you a working starting point.
Thank you very much Phoenix. Before using the configuration of my first message I had also tried the one you have mentioned, but the outcome is the same unfortunately. At this point, one hypothesis I have is that the token and the secret are not valid any more, but I wonder whether the error message I receive is the typical one for such cases,
@Cesco85 you should test whether the token and secret are valid using API calls. If you're having trouble using the client libraries for this, one way to do it is via the Postman collection: https://github.com/plaid/plaid-postman
Closing this issue out as it doesn't appear to be an issue with the client library. If you end up still needing help, feel free to file a support ticket via the dashboard.