Python Forum
want to know the kind of object whether its a python or json object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
want to know the kind of object whether its a python or json object
#4
You should use Requests.
Data payload to server is a Python dictionary.
Requests has build in json decoder,it will do encoding inn and out of server(can just call json()).
Eg:
>>> import requests
>>> data = {"device_name": "Super-pc", "Type": "DevicePort", "page_size": 2}
>>> r = requests.post('http://httpbin.org/post', json=data)
>>> r.status_code
200
>>> r.json()
{'args': {},
 'data': '{"device_name": "Super-pc", "page_size": 2, "Type": "DevicePort"}',
 'files': {},
 'form': {},
 'headers': {'Accept': '*/*',
             'Accept-Encoding': 'gzip, deflate',
             'Content-Length': '65',
             'Content-Type': 'application/json',
             'Host': 'httpbin.org',
             'User-Agent': 'python-requests/2.9.1'},
 'json': {'Type': 'DevicePort', 'device_name': 'Super-pc', 'page_size': 2},
 'origin': '83.143.86.75',
 'url': 'http://httpbin.org/post'}
>>> data = r.json()
>>> data['json'].get('device_name', 'Not on server')
'Super-pc'
>>> data['json'].get('hello', 'Not on server')
'Not on server'
Reply


Messages In This Thread
RE: want to know the kind of object whether its a python or json object - by snippsat - Jan-21-2017, 07:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing out incidence values for Class Object SquderDragon 3 333 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  This result object does not return rows. It has been closed automatically dawid294 6 1,241 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 466 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  How can I pause only one object? actualpy 1 401 Feb-01-2024, 07:43 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 582 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Question Chain object that have parent child relation.. SpongeB0B 10 1,155 Dec-12-2023, 01:01 PM
Last Post: Gribouillis
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 792 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,097 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,478 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,833 Aug-04-2023, 12:41 PM
Last Post: Konstantin23

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020