Calling model API using curl command

tasneem.ghayastasneem.ghayas Member Posts: 10

Hi,

I have a question regarding model api. The query data is long so I store that into a file and read it into "data" key using Python. I receive the intended response with Python.

import requests
import json
with open('xyz.txt', encoding='latin-1') as f:
   data = json.load(f)
response=requests.post(url ,auth=("id","key"),json={"data":{'jsoninput':data}},verify=False)
print(response.json())

If I call the same API using curl I get an error.

  1. I pass the data file to the -d option
  2. I have tried also store the file in a var and pass that to 'data' key but it does not work either.

curl -k 'url' -H 'Content-Type: application/json' -d '@Jsoninput_S2.txt' -u key:key

I This is the error I receive:
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>
Tagged:

Answers

  • pankhuri.vermapankhuri.verma Member, Administrator, Moderator, Domino Posts: 16 admin

    Hi Tasneem, Does the file Jsoninput_S2.txt file have the same format as -

    {"data":{'jsoninput':data}}
    


  • tasneem.ghayastasneem.ghayas Member Posts: 10
    edited September 22

    yes it does

  • tasneem.ghayastasneem.ghayas Member Posts: 10

    @pankhuri.verma Any updates?

  • pankhuri.vermapankhuri.verma Member, Administrator, Moderator, Domino Posts: 16 admin

    Hi Tasneem, Sorry I haven't had a chance to look at this. Can you try the below Curl command and see if that resolves the issue -

    curl -k 'url' -H 'Content-Type: application/json' -F json="Jsoninput_S2.txt" -u key:key

  • tasneem.ghayastasneem.ghayas Member Posts: 10

    i have tried this already and it does not work

  • pankhuri.vermapankhuri.verma Member, Administrator, Moderator, Domino Posts: 16 admin

    HI Tasneem, Can you please open a ticket with Domino ? I think I will be able to help you out better on the ticket by having a screenshare and looking at what could be missing. The 400 Bad request typically points to a syntax error, and without all the information - the whole code, the data you are parsing etc I am unable to provide solution. I am conscious this is a public forum, so I haven't asked for such sensitive details.

Sign In or Register to comment.