Converting a working CURL put command to Python - json

I have a working curl command that uploads a csv on my local server to a remote Artifactory server which will host the csv. I have a need to convert it to Python using the requests library as I am trying to integrate it into a bigger script. I'm unable to get it to work in Python because I'm getting a "405" error. Does anyone have any idea how i could get it to work in Python please? My working curl code example is below:
curl -H "Authorization: Bearer fsdfsfsfsdvsdvsdvsviQ" -X PUT "http://art.test.lan/artifactory/report/test.csv" -T test.csv
The code I created to convert the above working code using Python requests which is giving me
the 405 is below:
import requests
headers = {
'Authorization': 'Bearer fsdfsfsfsdvsdvsdvsviQ',
}
url = 'http://art.test.lan/artifactory/report'
files = {'file': open('test.csv', 'rb')}
response = requests.post(url=url, files=files)
print(response)
print(response.text)```

The comment from above
"you can try requests.put()" – from techytushar took care of this issue

Related

How do we to get JSON content in the response body of freshservice webservice?

I am doing automation to get opening tickets details so i am executing web service call in FreshService ticketing tool.
Below is my web service call using CURL and GET
curl -X GET -H 'Content-Type: application/json' -v -i 'https://support.XXXXXXX.com/helpdesk/tickets/9725.json?-u=ASDDDECDFF%3AX%20'
When i am executing only getting below response in body.
{
"require_login":True
}
But my output joson file visible after opening that url in browse i can see json file, so i execute below vbsctipt to send HTTP request for read the JSON file but same ""Require_login":True" coming.
Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "https://support.XXXXXXX.com/helpdesk/tickets/9723.json", False
o.send
msgbox o.responseText
So my expectation to get JSON file in body part of web service response or through vbscript get JSON file store locally.
Appreciate any other light wight tool or easy approach. More about Fresh service API details https://api.freshservice.com/#introduction
After i encoded my authentication key with base64 and addd Authorization as header and its working now.
Update Web service URL,
curl -X GET -H 'Content-Type: application/json' -H 'Authorization: Basic XXXXXYYYYYZZZ' -v -i 'https://support.XXXXX.com/helpdesk/tickets.json'

Uploading a file to storage location(bucket)

I tried uploading the file using postman ,curl command in windows and linux mentioned in the url https://forge.autodesk.com/en/docs/data/v2/tutorials/upload-file/ but getting gateway timeout error.
I followed the steps in the url https://forge.autodesk.com/en/docs/data/v2/tutorials/upload-file/. I am able to create bucket. But when I tried uploading file to the created bucket its giving 504 gateway timeout error.
Can you give me the solution to resolve this?
Screenshot attached for error
Please find request below:
curl -v 'https://developer.api.autodesk.com/oss/v2/buckets/testbucket/objects/test.3ds' -X 'PUT' -H 'Authorization: Bearer TOKEN' -H 'Content-Type: application/octet-stream' -H 'Content-Length: 308331' -T 'test.3ds'
It looks like the size of your model file is too big to upload, please use the resumable upload API instead, see the related thread here Upload large files (2GB) to Autodesk Forge Data Management API

How to convert a curl url to POSTMAN Request

I have a curl link which is successfully run with terminal but i want to convert it as a POSTMAN request where link is,
curl -H "Content-type:application/json" -X POST -u ApiUserAdmin:1234 http://10.20.10.50/API/TaskHandle -d "{\"event\":\"evening\",\"wish\":\"Good Evening\"}" &
and when i import it it gives ,
Error while importing Curl: 2 option-less arguments found. Only one is supported (the URL)
and when i convert it in mannually like,
and header is like
Then it gives error,
How to i solve the ApiUserAdmin and password.
Thanks in advance.
It looks like you're putting the username/password in the wrong section. Move it from the Header tab on Postman to the Authorization tab. Try selecting "Basic Auth" from the Type dropdown and putting the username/password in the fields that show up.

Google Drive Resumable Uploads

I am having trouble requesting the current status of a resumable upload. Based on the Google Documentation, the following request should return a Range header with the current range google has of my upload, but I keep getting the following response:
Failed to parse Content-Range header
Here is my curl request:
curl -H "Content-Range: bytes */1443452365" -H "Content-Length: 0" locationUrl -X PUT
I have also tried "bytes */*" and "*/*" for the Content-Range header, but no luck.
Any ideas?
First, you need to check the correct request format like the sample given below:
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":100}' http://localhost/api/postJsonReader.do
And, discussed in other command-line tools, when sending raw HTTP data, be aware that the POST and PUT operations will require computing the value for a Content-Length header. You can use the UNIX tool wc to compute this value. Place all the content of the HTTP body into a text file such as template_entry.xml (example used above) and run wc -c template_entry.xml. It is often difficult to debug if you accidentally use an incorrect value for the Content-Length header.
Lastly, you can request the status between chunks, not just if the upload is interrupted. If the upload request is interrupted, follow the procedure outlined in resume an interrupted upload.

Drupal JSON Server and Services Module only returns Invalid Method

I have been trying to get a stock Drupal site up and running with JSON Server module and Services. After install I added the two modules and enabled them. When I use Curl from the command line to call system.connect or anything I only get Invalid Method.
curl --data method=system.connect http://localhost/services/json
This is what I am getting back.
{ "#error": true, "#data": "Invalid method " }
I remember having the same problem myself a while back. Your problem at the moment is that your post data does not have quotes.
curl --data 'method="system.connect"' http://localhost/services/json
If you have a look at this: http://drupal.org/node/305799 it should give you loads more info to get you going with services and the json server.