Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
User guide/FAQ: Send JSON & URL-encoded requests to the App #1636
Comments
|
Hi Thanks for using Falcon. The large amount of time and effort needed to Please consider helping us secure the future of the Falcon framework with a Thank you for your support! |
|
Hi @yarin177 ! I would guess the problem is that you are sending your request payload as URL-encoded ( The following snippet works for me (I just extended your example slightly to showcase media, but your original responder is also left intact): import json
import falcon
class TextOcrRes:
def on_post(self, req, resp):
"""Handles Text POST requests"""
json_data = json.loads(req.bounded_stream.read().decode("utf-8"))
print(json_data)
class TextOcrMediaRes:
def on_post(self, req, resp):
"""Showcase Falcon media framework"""
print(req.media)
app = falcon.API()
app.add_route('/translate', TextOcrRes())
app.add_route('/translate2', TextOcrMediaRes())>>> requests.post('http://localhost:8000/translate', json={'image_data':'message1'})
<Response [200]>
>>> requests.post('http://localhost:8000/translate2', json={'image_data':'message2'})
<Response [200]>I'll leave the issue open for a while. |
|
Thank you, that solved the issue for me, and yes I'm sure it will be helpful if you can include an example for sending JSON in the tutorial. |
|
@yarin177 Whenever an applications expect it, or at least supports it, and you want to test it Although newly designed RESTful APIs typically prefer JSON (or YAML, Msgpack etc), |
about your other solution using media, I'm basically trying to send over an image from a client to the server and save it. but I don't know if I should send it with JSON or DATA or FILES
But How do I receive it on the server? do I need to encode it, JSON? |
|
Answered the sending image question on #1637. |


Hey, I'm trying to fetch out the data with JSON I've spent way too much time on google and tried every single solution with no success.. when I send the request it raises an json.decoder.JSONDecodeError Exception.
maybe can you help?
What I'm sending:
r = requests.post("http://x.xx.xx.xx/translate", data={'image_data':'message'})I'm on python 3.6.8