http-post

Getting "Method Not Allowed" when using fastapi

Getting "Method Not Allowed" when using fastapi Question: I am trying to run the following code but I am getting a {"detail":"Method Not Allowed"} error when I open http://localhost:8000/predict. The code: from fastapi import FastAPI app = FastAPI() @app.post("/predict") def predict_(request: str): return {"message": ‘Hellooo!’} What’s the problem with my code? I searched online for …

Total answers: 1

How to post an image file with a list of strings using FastAPI?

How to post an image file with a list of strings using FastAPI? Question: I have tried a lot of things, but it doesn’t seem to work. Here is my code: @app.post("/my-endpoint") async def my_func( languages: List[str] = ["en", "hi"], image: UploadFile = File(…) ): The function works fine when I remove one of the …

Total answers: 2

"detail": "Method "GET" not allowed." Django Rest Framework

"detail": "Method "GET" not allowed." Django Rest Framework Question: I know this question maybe a duplicate, but I have tried many solutions and could not understand any. I have followed this tutorial exactly and yet I get this error on the ‘userlist’ page. Everything else works just fine. Can somebody point out what the error …

Total answers: 4

Send Post request to an external API using AWS Lambda in python

Send Post request to an external API using AWS Lambda in python Question: I want to send a post request to an external API (https://example.com/api/jobs/test) every hour. The Lambda Function that I used is as follows: Handler: index.lambda_handler python: 3.6 index.py import requests def lambda_handler(event, context): url=”https://example.com/api/jobs/test” response = requests.post(url) print(response.text) #TEXT/HTML print(response.status_code, response.reason) #HTTP …

Total answers: 3

How to get all POST request values in Django?

How to get all POST request values in Django? Question: Is there any way get all the form names from a request in Django? <input type="text" name="getrow"> Html request def demoform(request): if request.method=="POST" inputtxt=request.POST.get("getrow") return HttpResponse(…) in the above I can get only from the name I know, what I need is to get all …

Total answers: 4

How to send JSON as part of multipart POST-request

How to send JSON as part of multipart POST-request Question: I have following POST-request form (simplified): POST /target_page HTTP/1.1 Host: server_IP:8080 Content-Type: multipart/form-data; boundary=AaaBbbCcc –AaaBbbCcc Content-Disposition: form-data; name=”json” Content-Type: application/json { “param_1”: “value_1”, “param_2”: “value_2″} –AaaBbbCcc Content-Disposition: form-data; name=”file”; filename=”…” Content-Type: application/octet-stream <..file data..> –AaaBbbCcc– I try to send POST-request with requests: import requests import …

Total answers: 3

TypeError: b'1' is not JSON serializable

TypeError: b'1' is not JSON serializable Question: I am trying to send a POST request as JSON. *email variable is of type “bytes” def request_to_SEND(email, index): url = “…..” data = { “body”: email.decode(‘utf-8’), “query_id”: index, “debug”: 1, “client_id”: “1”, “campaign_id”: 1, “meta”: {“content_type”: “mime”} } headers = {‘Content-type’: ‘application/json’} try: response = requests.post(url, data=json.dumps(data), …

Total answers: 1

How to receive json data using HTTP POST request in Django 1.6?

How to receive json data using HTTP POST request in Django 1.6? Question: I am learning Django 1.6. I want to post some JSON using HTTP POST request and I am using Django for this task for learning. I tried to use request.POST[‘data’], request.raw_post_data, request.body but none are working for me. my views.py is import …

Total answers: 3

Django returns 403 error when sending a POST request

Django returns 403 error when sending a POST request Question: when I’m using following Python code to send a POST request to my Django website I’m getting 403: Forbidden error. url = ‘http://www.sub.example.com/’ values = { ‘var’: ‘test’ } try: data = urllib.urlencode(values, doseq=True) req = urllib2.Request(url, data) response = urllib2.urlopen(req) the_page = response.read() except: …

Total answers: 7