Kucoin / kucoin-api-docs

KuCoin API Docs
Other
273 stars 147 forks source link

check_header_validity ERROR #378

Open vadimShlyapa opened 2 years ago

vadimShlyapa commented 2 years ago

This my code:

url = 'https://openapi-sandbox.kucoin.com/api/v1/deposit-addresses' now = int(time.time() * 1000) data = {"currency": "BTC"} data_json = json.dumps(data) str_to_sign = str(now) + 'POST' + '/api/v1/deposit-addresses' + data_json signature = base64.b64encode( hmac.new(api_secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).digest()) passphrase = base64.b64encode( hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest()) headers = { "KC-API-SIGN": signature, "KC-API-TIMESTAMP": str(now), "KC-API-KEY": api_key, "KC-API-PASSPHRASE": passphrase, "KC-API-KEY-VERSION": 2, "Content-Type": "application/json" # specifying content type or using json=data in request } response = requests.request('post', url, headers=headers, data=data_json) print(response.status_code) print(response.json())

This my output console:

Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\utils.py", line 1024, in check_header_validity if not pat.match(value): TypeError: expected string or bytes-like object

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Admin\Documents\API-KuCoin\test\index2.py", line 30, in response = requests.request('post', url, headers=headers, data=data_json) File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\sessions.py", line 515, in request prep = self.prepare_request(req) File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\sessions.py", line 443, in prepare_request p.prepare( File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\models.py", line 319, in prepare self.prepare_headers(headers) File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\models.py", line 453, in prepare_headers check_header_validity(header) File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\utils.py", line 1027, in check_header_validity raise InvalidHeader("Value for header {%s: %s} must be of type str or " requests.exceptions.InvalidHeader: Value for header {KC-API-KEY-VERSION: 2} must be of type str or bytes, not <class 'int'>

Where I have mistakes ? Please help me

progressivehed commented 2 years ago

Hello there

Have you imported the necessary modues?

Sample code is correct.