![]() |
|
[Python] Get Requests JSON parse dictionary issue... - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Get Requests JSON parse dictionary issue... (/showthread.php?tid=6070469) |
Get Requests JSON parse dictionary issue... - Xogg - Apr 23, 2020 Sooo I know the title is insane, let me explain. Im download a post request, parsing it into json then attempting to get certain data from it. This is my current code Code r = requests.get("https://shoppy.gg/api/v1/orders/", headers=headers)Ofc there is more before it but it doesent matter... so my issue is when I print the key I want to access a certain part of the data. This works with one peice, but not another.. Here is an example of what the key looks like. Code {'id': 'd781fbfe-f746-4b7-a990-9eaa2887894d', 'pay_id': None, 'product_id': 'pfFjYt', 'coupon_id': None, 'price': 10, 'currency': 'USD', 'exchange_rate': None, 'email': '[email protected]', 'delivered': 0, 'confirmations': 0, 'required_confirmations': 1, 'transaction_id': '', 'crypto_address': '[email protected]', 'crypto_amount': '10', 'shipping_address': None, 'quantity': 1, 'gateway': 'PayPal', 'custom_fields': [{'name': 'Discord Name (FULL NAME WITH #)', 'type': 'text', 'required': True, 'value': 'I NEED THIS PORTION OF DATA'}], 'refund_id': None, 'is_replacement': False, 'replacement_id': None, 'paid_at': None, 'disputed_at': None, 'created_at': '2020-04-23T09:47:41.000000Z', 'is_partial': None, 'crypto_received': None, 'return_url': None, 'coupon': [], 'product': {'id': 'xxxx', 'attachment_id': None, 'title': 'XXXX', 'description': None, 'image': None, 'unlisted': False, 'type': 'service', 'price': 10, 'currency': 'USD', 'email': {'enabled': False}, 'stock_warning': 0, 'quantity': {'min': 1, 'max': 1}, 'confirmations': 3, 'custom_fields': [{'name': 'Discord Name (FULL NAME WITH #)', 'type': 'text', 'required': True}], 'gateways': ['PayPal'], 'webhook_urls': [None], 'dynamic_url': '', 'position': None, 'created_at': '2020-04-23T09:36:58.000000Z', 'updated_at': '2020-04-23T09:36:58.000000Z', 'stock': 9223372036854775807, 'accounts': []}, 'agent': {'geo': {'ip': 'XXXX', 'iso_code': 'US', 'country': 'United States', 'city': 'XXXXX', 'state': 'XX', 'state_name': 'XXXX', 'postal_code': 'XXXX', 'lat': XXXX, 'lon': XXXX, 'timezone': 'America/New_York', 'continent': 'NA', 'currency': 'USD', 'default': True, 'cached': False}, 'data': {'is_mobile': False, 'is_tablet': False, 'is_desktop': True, 'platform': 'Windows', 'browser': {'name': 'Chrome', 'version': '81.0.4044.122'}, 'device': {'name': 'WebKit', 'version': False}}}, 'hash': 'd2f1b70fac94c3790ca9253934924e794d6fc4aa6277ea0d401b5d7b0f759cce'}So. Im trying to print this portion of data out. 'value': 'I NEED THIS PORTION OF DATA' if I do Code print(key['id'])BUTTTTT IF i do Code print(key['value'])Solved my issue! Code r = requests.get("https://shoppy.gg/api/v1/orders/", headers=headers)RE: Get Requests JSON parse dictionary issue... - SIM-1866423 - Apr 23, 2020 Code data = {"custom_fields":[{'name': 'Discord Name (FULL NAME WITH #)', 'type': 'text', 'required': True, 'value': 'I NEED THIS PORTION OF DATA'}]}did u try like this ? ur code ugly. RE: Get Requests JSON parse dictionary issue... - Lindros - Apr 24, 2020 In my IDE I get this when I copy past that dictionary. Code NameError: name 'XXXX' is not definedThat's not a properly structured python dictionary, it's super disorganized. It has all sorts of issues with it. |