Python: Got AttributeError when accessing App Store Connect API using appstoreconnect library

I created a small Python program to get data via the App Store Connect API for report automation with the appstoreconnect library. After update recently, I got the following error.

 1Traceback (most recent call last):
 2  File "/app/./main.py", line 88, in <module>
 3    APP_STORECONNECT_API.execute()
 4  File "/app/app_store_connect.py", line 176, in execute
 5    api = Api(self.API_KEY, self.CERT_FILE, self.ISSUER_ID)
 6  File "/usr/local/lib/python3.9/site-packages/appstoreconnect/api.py", line 51, in __init__
 7    token = self.token  # generate first token
 8  File "/usr/local/lib/python3.9/site-packages/appstoreconnect/api.py", line 269, in token
 9    self._token = self._generate_token()
10  File "/usr/local/lib/python3.9/site-packages/appstoreconnect/api.py", line 64, in _generate_token
11    return jwt.encode({'iss': self.issuer_id, 'exp': exp, 'aud': 'appstoreconnect-v1'}, key,
12AttributeError: 'str' object has no attribute 'decode'

It depends on the above error, the problem happened here.

https://github.com/Ponytech/appstoreconnectapi/blob/0916ac75790b13cf6c89617209a1a6c2db1f16d1/appstoreconnect/api.py#L79-L80

And the author already realized about this issue.

https://github.com/Ponytech/appstoreconnectapi/issues/37

He said the cause of the problem is the type of return value was changed in the JWT library from byte to string since 2.0. So, I thought I should specify a version of JWT which is the latest before 2.0. And then, I checked the version history here.

https://pypi.org/project/PyJWT/#history

The latest 1.x version is 1.7.1 so I specified it explicitly when executing the pip command in my Dockerfile like this.

1pip install PyJWT==1.7.1

The problem was solved. So, this is one of the workarounds for now about this issue.