I am writing a script under the Qiwi API. When sending a request, if the number of payments does not fit into the size of the requested information (from 1 to 50), you must send a new request with certain parameters.
Here is the query:
"https://edge.qiwi.com/payment-history/v2/persons/79112223344/payments?rows=50&nextTxnId=9103121&nextTxnDate=2017-05-11T12%3A35%3A23%2B03%3A00" From the previous query, I got json, from which I pulled the values:
next_txn_date: 2018-12-24T23:28:05+03:00 next_txn_id: 14552442122 How do I cast next_txn_date to the form that is in the request. As I understand it, you need to convert special characters
I send requests requests library.
Here is what error comes when sending a request
{'serviceName': 'payment-history', 'errorCode': 'validation.error', 'description': 'Validation error', 'userMessage': 'Validation error', 'dateTime': '2018-12-26T11:29:51.578+03:00', 'traceId': '0e1200e77a2877d9', 'cause': {'nextTxnDate': ['Wrong date format']}} Code:
header = {"Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + token} root_url = "https://edge.qiwi.com/" def get_payment_list(self): url = root_url + "payment-history/v2/persons/" + login + "/payments?rows=1" json_text = requests.get(url, headers=header).json() print(json_text) while True: try: next_txn_id = json_text["nextTxnId"] next_txn_date = json_text["nextTxnDate"] if((next_txn_id is not None) and (next_txn_date is not None)): print("next_txn_date", next_txn_date) print("next_txn_id ", next_txn_id) next_url = root_url + "payment-history/v2/persons/" + login + "/payments?rows=1&nextTxnId=" + str(next_txn_id) +"&nextTxnDate=" + next_txn_date json_text = requests.get(next_url, headers=self.header).json() print(json_text) else: break except KeyError: print("Превышение лимита запросов (100). Блокировка на 5 минут") time.sleep(301) Json, from the first request:
{'data': [{'txnId': 14552452204, 'personId': 79822304501, 'date': '2018-12-24T23:31:05+03:00', 'errorCode': 0, 'error': None, 'status': 'SUCCESS', 'type': 'OUT', 'statusText': 'Success', 'trmTxnId': '992754691630', 'account': '+79295320477', 'sum': {'amount': 12730, 'currency': 643}, 'commission': {'amount': 0, 'currency': 643}, 'total': {'amount': 12730, 'currency': 643}, 'provider': {'id': 99, 'shortName': 'Перевод на QIWI Кошелек', 'longName': 'Доставляется мгновенно', 'logoUrl': 'https://static.qiwi.com/img/providers/logoBig/99_l.png', 'description': None, 'keys': 'пополнить, перевести, qiwi, кошелек, оплатить, онлайн, оплата, счет, способ, услуга,перевести', 'siteUrl': 'http://www.qiwi.com', 'extras': [{'key': 'ceo_description', 'value': 'Пополнение QIWI Кошелька банковской картой без комисии, со счета мобильного телефона или через крупнейшую сеть QIWI Терминалов. Оплачивать услуги стало проще.'}, {'key': 'ceo_title', 'value': 'Пополнить QIWI Кошелек: с банковской карты, с баланса телефона, через QIWI Кошелек'}, {'key': 'is_spa_form_available', 'value': 'true'}]}, 'source': {'id': 7, 'shortName': 'QIWI Кошелек', 'longName': 'QIWI Кошелек', 'logoUrl': None, 'description': None, 'keys': 'мобильный кошелек, кошелек, перевести деньги, личный кабинет, отправить деньги, перевод между пользователями', 'siteUrl': None, 'extras': []}, 'comment': '#3496378#', 'currencyRate': 1, 'paymentExtras': [], 'features': {'chequeReady': True, 'bankDocumentReady': False, 'regularPaymentEnabled': True, 'bankDocumentAvailable': False, 'repeatPaymentEnabled': True, 'favoritePaymentEnabled': True, 'chatAvailable': True, 'greetingCardAttached': False}, 'serviceExtras': {}, 'view': {'title': 'Перевод на QIWI Кошелек', 'account': '+79295320477'}}], 'nextTxnId': 14552442122, 'nextTxnDate': '2018-12-24T23:28:05+03:00'}
Wrong date format. Is the date string correct? And so, trynext_txn_dateprocess throughquote(from urllib.parse import quote) - gil9redquote. Better pass your parameters throughparams. Example: github.com/gil9red/SimplePyScripts/blob/ ... There you will need to give the dictionary - gil9red