We currently have a cURL request like below and we'd like to convert it into Python. How do I do this? From my googling, all I am seeing is how to send files but not a folder files. Thank you!
curl
--location
--request PUT 'https://some-url.com/files' \
--header 'Content-Type: application/octet-stream' \
--data-binary '#/path/to/files'
Related
I'm trying to execute some curl POST commands to a SSH server using Paramiko.
The problem is that the curl command includes quotes and simple quotes and some extra characters are added when sending the command to the server.
What I try to send is the following:
ssh.exec_command("curl -X POST -H 'Content-Type: application/json' -d '{\"backlight\":true}' [127.0.0.1]")
Server answers with invalid JSON. I checked it and what reaches the server is:
curl -X POST -H \'Content-Type: application/json\' -d \'{"backlight":true}\' [127.0.0.1]
There are some backslashes added to my string, so that the curl command is invalid.
I tried a lot of things like escaping, replace(), change the command etc. nothing worked.
Do you have any tips or ideas how to solve this issue? It's really frustrating.
Server command should look like this:
curl -X POST -H 'Content-Type: application/json' -d '{"backlight":true}' [127.0.0.1]
I am sending a avro file as binary data to a flask application. The flask application is running in a container with python 3.6.
When I use the image in my local environment is working fine. I am getting the proper response. But when I deploy the image to kubernates, for some weird reason I am not able to decode the avro payload. Not sure what is related to the encode or the SO running the container.
For send the data I am using the following curl command:
curl --location --request POST 'https://foo/endpoint' \
--header 'Content-Type: application/avro;charset=UTF-8' \
--header 'Accept: application/avro+json' \
--data-binary '#c:/blabla/file.avro'
In my flask application I am receiving the request as:
#application.route('/endpoint', methods=['POST'])
def get_attributes_response(foo):
res= request.get_data()
Thanks!!!
I'm working on a Python 3.6 project in which I need to create a repository on the docker hub account by using API. I have googled a lot but couldn't find any API client to create repositories on docker hub account.
I have found only this module dockercloud from here and tried it in this way:
dockercloud.user = 'arycloud'
dockercloud.apikey = 'API_KEY'
print(client.Repository.list())
But it returns an error like this:
dockercloud.api.exceptions.AuthError: error getting credentials - err: exec: "docker-credential-osxkeychain": executable file not found in $PATH, out: ``
Is there any way to create a repo on Docker Hub using API?
The API documentation does not describe any mechanism for creating repositories on any registry, Docker Hub included.
However, I was able to create a repository using curl to send a POST request:
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -s -H "Authorization: JWT ${TOKEN}" "https://hub.docker.com/v2/repositories/" \
--data 'description=test' \
--data 'full_description=full-description' \
--data 'is_private=false' \
--data 'name=test' \
--data "namespace=${UNAME}"
I am trying to convert the below code in curl to python2 urllib2 request call for performing a "PUT" operation, it works fine with cURL but i am clueless on getting this converted to python2 code.
cURL
curl -X PUT -u myUser:myPassword -T test.txt “http://localhost:8081/artifactory/libs-release-local/test/test.txt”
The problem i face is with the "-T" flag i am not sure how set this in urllib2 call. I tried using Postman for help by adding file to Body->form-data->file
But the code is converted as below which i suspect is not the transfer file call.
curl -X PUT \
http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: 4ffbfca4-a4be-09de-c8ab-0731a2d67009' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F '=#C:\Devops\file.txt'
I tried looking at documentations specified here under -T/--upload-file it does not help. Any suggestions.
https://www.computerhope.com/unix/curl.html
https://curl.haxx.se/libcurl/c/options-in-examples.html
Python newb here, here's my current script:
#!/usr/bin/env python
import os
import time
import datetime
import subprocess
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime(%Y%m%d)
My curl command:
curl -i -k -H -o <timestamp>.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:******" -H "appKey:*******" -X GET https://*****.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=******&term_from=<timestamp>
The dynamic aspect of this curl request comes from the python portion of my script. I need the output file to be the $currentTime.txt and i need the php variable $term_from to also be the timestamp.
So far ive tried invoking the curl command using
os.system('curl -i -k -H -o' + %st + '.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:arcsght_app" -H "appKey:*****" -X GET https://csopen.teamaol.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=Dulles&term_from=' + %st)
That didn't work, then i tried using
subprocess.call(<same curl command as above>)
and that didnt work.
Ive tried my curl command from bash and it works, and i can get my timestamp to show how i need it. I just cant figure out how to tie everything together. Before i posted this i did try to figure it out on my own, but this is my first real adventure into python so my knowledge of what works and what doesn't is pretty slim. Looking for help! Thanks.
my_command = 'curl -i -k -H -o {timestamp}.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:******" -H "appKey:*******" -X GET https://*****.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=******&term_from={timestamp}'.format(timestamp=123456)
os.system(my_command)
should work fine ... Im not entirely sure why you want to do this in python... but this should allow you to no problem