Repository: cuenca-mx/cuenca-python (language: python)

Issue:
CuencaResponseException: CuencaResponseException(json={'error': 'Expired signature'}, status_code=401)
Sentry Issue: [CUENCA-4B0](https://sentry.io/organizations/cuenca-mx/issues/2533031792/?referrer=github_integration)

```
CuencaResponseException: CuencaResponseException(json={'error': 'Expired signature'}, status_code=401)
(9 additional frame(s) were not displayed)
...
  File "cuenca/jwt.py", line 45, in create
    token = session.post('/token', dict())['token']
  File "cuenca/http/client.py", line 84, in post
    return self._request_json('post', endpoint, data=data)
  File "cuenca/http/client.py", line 93, in _request_json
    return json.loads(self.request(*args, **kwargs))
  File "cuenca/http/client.py", line 115, in request
    self._check_response(resp)
  File "cuenca/http/client.py", line 127, in _check_response
    status_code=response.status_code,
```


Discussion / hints:

Fix patch:
diff --git a/cuenca/jwt.py b/cuenca/jwt.py
index 3bf40a8d..c7390c2a 100644
--- a/cuenca/jwt.py
+++ b/cuenca/jwt.py
@@ -42,6 +42,7 @@ def get_expiration_date(token: str) -> dt.datetime:
     @classmethod
     def create(cls, session: 'Session') -> 'Jwt':
         session.jwt_token = None
+        session.session.headers.pop('X-Cuenca-Token', None)
         token = session.post('/token', dict())['token']
         expires_at = Jwt.get_expiration_date(token)
         return cls(expires_at, token)
diff --git a/cuenca/version.py b/cuenca/version.py
index aecf5e0b..529befce 100644
--- a/cuenca/version.py
+++ b/cuenca/version.py
@@ -1,3 +1,3 @@
-__version__ = '0.7.12'
+__version__ = '0.7.13'
 CLIENT_VERSION = __version__
 API_VERSION = '2020-03-19'


Test patch:
diff --git a/tests/http/cassettes/test_request_expired_token.yaml b/tests/http/cassettes/test_request_expired_token.yaml
index 1b4e041d..d8f6f87b 100644
--- a/tests/http/cassettes/test_request_expired_token.yaml
+++ b/tests/http/cassettes/test_request_expired_token.yaml
@@ -1,6 +1,6 @@
 interactions:
 - request:
-    body: null
+    body: '{}'
     headers:
       Accept:
       - '*/*'
@@ -11,38 +11,32 @@ interactions:
       Connection:
       - keep-alive
       Content-Length:
-      - '0'
+      - '2'
+      Content-Type:
+      - application/json
       User-Agent:
-      - cuenca-python/0.3.6
+      - cuenca-python/0.7.12
       X-Cuenca-Api-Version:
       - '2020-03-19'
     method: POST
     uri: https://api.cuenca.com/token
   response:
     body:
-      string: '{"id":12,"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MDM5MTA5NDksImlhdCI6MTYwMzMwNjE0OSwic3ViIjoiQUtib3hCeXNTd1NTbVR0VmtoT1I2X21RIiwidWlkIjoiMWFkNWUwZTMtMTNjZS0xMWViLTg0MjItNDE3MmZhYTQwZjQyIn0.5OX-MCcgi4cyiGexSsDIwk8HyhJxuIT8VF7X41GkO6w","created_at":"2020-10-21T18:49:09.935845","api_key":{"id":"AKboxBysSwSSmTtVkhOR6_mQ","created_at":"2020-10-20T23:56:28.845757","secret":"********","deactivated_at":null,"user_id":"rsc"}}'
+      string: '{"id":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzQ3NzMwNzEsImlhdCI6MTYzNDc3MzAxMSwic3ViIjoiQUtRRXJUbXdlZFFxQ0xwQ2plWkc4c0pRIiwidWlkIjoiOTljZDMyYTItMzFmZS0xMWVjLTgyMGEtMDI0MmFjMTEwMDAyIn0.EjDd6PpYWLCsuYhd98CdBCj6fThrVWX_X4uNW_tKVpg","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzQ3NzMwNzEsImlhdCI6MTYzNDc3MzAxMSwic3ViIjoiQUtRRXJUbXdlZFFxQ0xwQ2plWkc4c0pRIiwidWlkIjoiOTljZDMyYTItMzFmZS0xMWVjLTgyMGEtMDI0MmFjMTEwMDAyIn0.EjDd6PpYWLCsuYhd98CdBCj6fThrVWX_X4uNW_tKVpg","created_at":"2021-10-20T23:36:51.346137","api_key_uri":"/api_key/AKQErTmwedQqCLpCjeZG8sJQ"}'
     headers:
-      Connection:
-      - keep-alive
-      Content-Length:
-      - '438'
-      Content-Type:
+      content-length:
+      - '576'
+      content-type:
       - application/json
-      Date:
-      - Wed, 21 Oct 2020 18:49:09 GMT
-      Server:
-      - nginx/1.18.0
-      X-Amzn-Trace-Id:
-      - Root=1-5f9082a5-37ce7b1275ae2055215eb14d;Sampled=0
-      x-amz-apigw-id:
-      - UxlZ8FEyCYcFUuQ=
-      x-amzn-RequestId:
-      - ee534c24-2878-4efe-b91e-3c99757adff6
+      date:
+      - Wed, 20 Oct 2021 23:36:50 GMT
+      server:
+      - uvicorn
     status:
       code: 201
       message: Created
 - request:
-    body: null
+    body: '{}'
     headers:
       Accept:
       - '*/*'
@@ -53,35 +47,27 @@ interactions:
       Connection:
       - keep-alive
       Content-Length:
-      - '0'
+      - '2'
+      Content-Type:
+      - application/json
       User-Agent:
-      - cuenca-python/0.3.6
+      - cuenca-python/0.7.12
       X-Cuenca-Api-Version:
       - '2020-03-19'
-      X-Cuenca-Token:
-      - DUMMY
     method: POST
     uri: https://api.cuenca.com/token
   response:
     body:
-      string: '{"id":13,"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MDM5MTA5NTAsImlhdCI6MTYwMzMwNjE1MCwic3ViIjoiQUtib3hCeXNTd1NTbVR0VmtoT1I2X21RIiwidWlkIjoiMWFlMjQ5MjUtMTNjZS0xMWViLTk0ZDQtNDE3MmZhYTQwZjQyIn0.GmDxVfvt2Es6mf1upY5Y7RdkGgeos7mTpA_7wFb8ZaI","created_at":"2020-10-21T18:49:10.017165","api_key":{"id":"AKboxBysSwSSmTtVkhOR6_mQ","created_at":"2020-10-20T23:56:28.845757","secret":"********","deactivated_at":null,"user_id":"rsc"}}'
+      string: '{"id":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzQ3NzMwNzEsImlhdCI6MTYzNDc3MzAxMSwic3ViIjoiQUtRRXJUbXdlZFFxQ0xwQ2plWkc4c0pRIiwidWlkIjoiOWExZDI0NDItMzFmZS0xMWVjLTgyMGEtMDI0MmFjMTEwMDAyIn0.cJ_W7Dbn7M1w2yNDHwSxa92iqT-twpUwNIFoHOHaNV8","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzQ3NzMwNzEsImlhdCI6MTYzNDc3MzAxMSwic3ViIjoiQUtRRXJUbXdlZFFxQ0xwQ2plWkc4c0pRIiwidWlkIjoiOWExZDI0NDItMzFmZS0xMWVjLTgyMGEtMDI0MmFjMTEwMDAyIn0.cJ_W7Dbn7M1w2yNDHwSxa92iqT-twpUwNIFoHOHaNV8","created_at":"2021-10-20T23:36:51.870084","api_key_uri":"/api_key/AKQErTmwedQqCLpCjeZG8sJQ"}'
     headers:
-      Connection:
-      - keep-alive
-      Content-Length:
-      - '438'
-      Content-Type:
+      content-length:
+      - '576'
+      content-type:
       - application/json
-      Date:
-      - Wed, 21 Oct 2020 18:49:10 GMT
-      Server:
-      - nginx/1.18.0
-      X-Amzn-Trace-Id:
-      - Root=1-5f9082a5-25f2f46b7c8b558769ecf708;Sampled=0
-      x-amz-apigw-id:
-      - UxlZ8Gs5CYcFtFg=
-      x-amzn-RequestId:
-      - 6553d156-d57e-48a4-b16a-42588c221827
+      date:
+      - Wed, 20 Oct 2021 23:36:50 GMT
+      server:
+      - uvicorn
     status:
       code: 201
       message: Created
@@ -92,10 +78,12 @@ interactions:
       - '*/*'
       Accept-Encoding:
       - gzip, deflate
+      Authorization:
+      - DUMMY
       Connection:
       - keep-alive
       User-Agent:
-      - cuenca-python/0.3.6
+      - cuenca-python/0.7.12
       X-Cuenca-Api-Version:
       - '2020-03-19'
       X-Cuenca-Token:
@@ -104,24 +92,16 @@ interactions:
     uri: https://api.cuenca.com/api_keys
   response:
     body:
-      string: '{"items":[{"id":"AKboxBysSwSSmTtVkhOR6_mQ","created_at":"2020-10-20T23:56:28.845757","secret":"********","deactivated_at":null,"user_id":"rsc"}],"next_page_uri":null}'
+      string: '{"items":[{"id":"AKSIiEK7vWQRiea1VAJZpQRA","created_at":"2021-04-06T00:42:59.852000","secret":"********","deactivated_at":"2212-12-01T00:28:40.075000","user_id":"USaNW8apNBSc-FiOWMX9NEKg","updated_at":"2021-04-06T00:28:40.075000"},{"id":"AKBCEuSw11RSmwhwL_I1UrHg","created_at":"2021-04-06T00:36:25.322000","secret":"********","deactivated_at":"2212-12-01T00:28:40.075000","user_id":"USaNW8apNBSc-FiOWMX9NEKg","updated_at":"2021-04-06T00:28:40.075000"},{"id":"AKQErTmwedQqCLpCjeZG8sJQ","created_at":"2021-02-21T05:24:08.060000","secret":"********","deactivated_at":"2212-10-18T05:21:09.897000","user_id":"USaNW8apNBSc-FiOWMX9NEKg","updated_at":"2021-02-25T23:12:05.812000"}],"next_page_uri":null}'
     headers:
-      Connection:
-      - keep-alive
-      Content-Length:
-      - '166'
-      Content-Type:
+      content-length:
+      - '695'
+      content-type:
       - application/json
-      Date:
-      - Wed, 21 Oct 2020 18:49:10 GMT
-      Server:
-      - nginx/1.18.0
-      X-Amzn-Trace-Id:
-      - Root=1-5f9082a6-6a70a6d03f0698b549541398;Sampled=0
-      x-amz-apigw-id:
-      - UxlZ9G4tiYcFmjQ=
-      x-amzn-RequestId:
-      - e3f54e5b-13ec-4cf8-83da-4f93f7bd9c54
+      date:
+      - Wed, 20 Oct 2021 23:36:50 GMT
+      server:
+      - uvicorn
     status:
       code: 200
       message: OK