TypeError when using link_token_create
jsbrich opened this issue · 1 comments
Using the latest release (2.3.3) of the plaid python api
@app.route('/api/create_link_token', methods=['POST'])
def create_link_token():
user_id = time.time()
if(request.data):
req = request.json
user_id = req['userId']
if(user_id is not None):
try:
linkRequest = LinkTokenCreateRequest(
products=[Products("auth"), Products("transactions")],
client_name="JNetInc PFM",
country_codes=[CountryCode("US")],
language="en",
user=LinkTokenCreateRequestUser(client_user_id=str(user_id)),
)
if PLAID_REDIRECT_URI!=None:
linkRequest['redirect_uri']=PLAID_REDIRECT_URI
# create link token
linkResponse = client.link_token_create(linkRequest)
pretty_print_response(linkResponse.to_dict())
return jsonify(linkResponse.to_dict())
except plaid.ApiException as e:
return json.loads(e.body)
else:
error = [{'error': 'Invlaid User ID Provided'}]
return jsonify(error, status=500, mimetype='application/json')
When this runs, I get
[Mon Sep 04 15:02:38.680726 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] [2023-09-04 15:02:38,674] ERROR in app: Exception on /api/create_link_token [POST]
[Mon Sep 04 15:02:38.680763 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] Traceback (most recent call last):
[Mon Sep 04 15:02:38.680769 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
[Mon Sep 04 15:02:38.680773 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] response = self.full_dispatch_request()
[Mon Sep 04 15:02:38.680777 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
[Mon Sep 04 15:02:38.680781 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] rv = self.handle_user_exception(e)
[Mon Sep 04 15:02:38.680785 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
[Mon Sep 04 15:02:38.680789 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] rv = self.dispatch_request()
[Mon Sep 04 15:02:38.680793 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
[Mon Sep 04 15:02:38.680797 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
[Mon Sep 04 15:02:38.680801 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/pfm_api.py", line 244, in create_link_token
[Mon Sep 04 15:02:38.680805 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] linkResponse = client.link_token_create(linkRequest)
[Mon Sep 04 15:02:38.680809 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/api/plaid_api.py", line 20564, in link_token_create
[Mon Sep 04 15:02:38.680827 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.link_token_create_endpoint.call_with_http_info(**kwargs)
[Mon Sep 04 15:02:38.680831 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/api_client.py", line 879, in call_with_http_info
[Mon Sep 04 15:02:38.680835 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.api_client.call_api(
[Mon Sep 04 15:02:38.680839 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/api_client.py", line 421, in call_api
[Mon Sep 04 15:02:38.680843 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.__call_api(resource_path, method,
[Mon Sep 04 15:02:38.680847 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/api_client.py", line 198, in __call_api
[Mon Sep 04 15:02:38.680851 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] response_data = self.request(
[Mon Sep 04 15:02:38.680869 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/api_client.py", line 467, in request
[Mon Sep 04 15:02:38.680873 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.rest_client.POST(url,
[Mon Sep 04 15:02:38.680892 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/rest.py", line 270, in POST
[Mon Sep 04 15:02:38.680897 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.request("POST", url,
[Mon Sep 04 15:02:38.680922 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/plaid/rest.py", line 156, in request
[Mon Sep 04 15:02:38.680927 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] r = self.pool_manager.request(
[Mon Sep 04 15:02:38.680931 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/_request_methods.py", line 118, in request
[Mon Sep 04 15:02:38.680935 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.request_encode_body(
[Mon Sep 04 15:02:38.680952 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/_request_methods.py", line 217, in request_encode_body
[Mon Sep 04 15:02:38.680956 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] return self.urlopen(method, url, **extra_kw)
[Mon Sep 04 15:02:38.680960 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/poolmanager.py", line 443, in urlopen
[Mon Sep 04 15:02:38.680964 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] response = conn.urlopen(method, u.request_uri, **kw)
[Mon Sep 04 15:02:38.680968 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
[Mon Sep 04 15:02:38.680972 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] response = self._make_request(
[Mon Sep 04 15:02:38.680976 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 496, in _make_request
[Mon Sep 04 15:02:38.680980 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] conn.request(
[Mon Sep 04 15:02:38.680984 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 394, in request
[Mon Sep 04 15:02:38.680988 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] self.putheader(header, value)
[Mon Sep 04 15:02:38.680992 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/var/www/wsgi/wsgi-scripts/pfm_api/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 308, in putheader
[Mon Sep 04 15:02:38.680996 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] super().putheader(header, *values)
[Mon Sep 04 15:02:38.681000 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] File "/usr/lib/python3.10/http/client.py", line 1260, in putheader
[Mon Sep 04 15:02:38.681004 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] if _is_illegal_header_value(values[i]):
[Mon Sep 04 15:02:38.681008 2023] [wsgi:error] [pid 34853] [remote 192.168.68.69:48922] TypeError: expected string or bytes-like object
Client is opened earlier as
configuration = plaid.Configuration(
host=host,
api_key={
'clientId': PLAID_CLIENT_ID,
'secret': PLAID_SECRET,
}
)
api_client = plaid.ApiClient(configuration)
client = plaid_api.PlaidApi(api_client)
I've tried hard-coding user_id to a string, I replaced all the code with the test_link_token_create_required()
in the test methods, always the same result. Little bit of digging shows some of the values in the "headers" are None, but I can't figure out where they are set.
I see this issue has been in here a couple of times, but either no answer is given, or the answer is an incorrect input. I can't find that any of the inputs are incorrect.
Issue was .env file with PLAID client id and such was not being loaded, so values were None. I assumed the client creation function would have faulted first for that.