Quick issue solving on GCF/Python (awards the first one who gives me a message that solves the problem )
- Status: Closed
- Prize: $10
- Entries Received: 5
- Winner: sriharivaila2000
Contest Brief
I am building a function with Python 3.9
・request.get_json() returns None
・400 error with -H "Content-Type: application/json"
・-d '{"message":"hello"}' doesn't even work
I tried request.json() as well.
What the hell is wrong?
Here is the code
```Python
def hello_world(request):
request_json = request.get_json(force=True)
return request_json['message']
```
$ functions-framework --target hello_world
*Also tried deploying the code on actual project but no luck.
```curl
curl -X POST -d '{"message":"hello"}' "http://localhost:8080/"
#500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
curl -X POST -H "Content-Type: application/json" -d '{"message":"hello"}' "http://localhost:8080/"
#<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
```
I've already built GCF with request.args/"GET" request and it works just fine.
Just strated challenging with POST and got this.
Recommended Skills
Top entries from this contest
-
sriharivaila2000 India
-
PcSofthelper Romania
-
Hobology India
-
yassinezero Morocco
-
albertoadell17 Egypt
Public Clarification Board
How to get started with contests
-
Post Your Contest Quick and easy
-
Get Tons of Entries From around the world
-
Award the best entry Download the files - Easy!