Using 'Requests' to retrieve (GET) multipart json/binary

Using 'Requests' to retrieve (GET) multipart json/binary

Postby strifecrafter » Fri Jun 10, 2016 3:17 pm

Hi,
I am attempting to test a REST application using Python and the Requests package.
The URL I am accessing is supposed to return a JSON part and a binary part.

I can retrieve the json part w/out any problems

>>> import requests
>>> headers = {'content-type': 'multipart/mixed'}
>>> url = "xx.xx.xx.xx/rest/path/to/data"
>>> r = requests.get(url, headers=headers)
>>> r.headers['content-type']
'application/json
>>> r.json()
{'timestamp': 1465566160924, 'org': 'MATT', 'functions': ['radio', '0'], 'groupid': '', 'msgseq': 0, 'namespace': 'STATUS', 'nodeid': 'C0EE400ABCC9', 'correlationid': 0, 'statuscode': 0, 'isbinarydata': True}

What I can't figure out is how to retrieve the elusive second part of my response.
The developer who wrote the code told me that as long as I format the request properly, it should respond with both a json part and a binary part.

Google searching on this topic results in endless questions about performing multipart POSTs with Request, but as far as I can tell, zilch questions/answers about GETs

Any pointers on how to retrieve the binary portion using Requests would be very much appreciated!

thanks!

Jim
Last edited by micseydel on Fri Jun 10, 2016 3:39 pm, edited 1 time in total.
Reason: Initial post lock.
strifecrafter
 
Posts: 2
Joined: Fri Jun 10, 2016 2:38 pm

Re: Using 'Requests' to retrieve (GET) multipart json/binary

Postby Ofnuts » Fri Jun 10, 2016 5:59 pm

Have you checked the content attribute of the answer? Is at least its size coherent with an additional binary content?
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: Using 'Requests' to retrieve (GET) multipart json/binary

Postby strifecrafter » Mon Jun 13, 2016 3:46 pm

Ofnuts wrote:Have you checked the content attribute of the answer? Is at least its size coherent with an additional binary content?



Yes,
unfortunately - it's the same data:

This is what I retrieve via '.json()'

{'statuscode': 0, 'org': 'MATT', 'msgseq': 0, 'groupid': '', 'isbinarydata': True, 'functions': ['radio', '0'], 'namespace': 'STATUS', 'correlationid': 0, 'nodeid': 'C0EE400ABCC9', 'timestamp': 1465832387683}

and this is what I retrieved after converting the binary contents of '.content' to a string

{"isbinarydata":true,"correlationid":0,"functions":["radio","0"],"groupid":"","msgseq":0,"namespace":"STATUS","nodeid":"C0EE400ABCC9","org":"MATT","statuscode":0,"timestamp":1465832387683}

I'm told by the developer of the application I'm trying to test that there should be additional data in the binary portion, so either I'm retrieving and decoding it incorrectly, or there is a bug in the application ;-)

thanks

Jim
strifecrafter
 
Posts: 2
Joined: Fri Jun 10, 2016 2:38 pm

Re: Using 'Requests' to retrieve (GET) multipart json/binary

Postby Ofnuts » Mon Jun 13, 2016 7:50 pm

Would you have a sample URL?
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to Web Development

Who is online

Users browsing this forum: No registered users and 2 guests