0

Sorry to ask such entry level question. I need to translate the following cURL into python language. I tried to use requests function, which failed. So could anyone give me some hints? Is it right to choose requests? Should I consider urllib? Thanks!

cURL code:

$ curl -k -u 'key:secret_key' -X POST https://api.picloud.com/file/new/ -d name=your_file_name

My bad attempt:

r = requests.put('https://api.picloud.com/file/new/',auth=(api_key,api_secretkey),data={'name':'your_file_name'})

I got the following errors:

requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Do I need to encoded my key and secret key first?

Jeremy
  • 1
  • 85
  • 340
  • 366
TTT
  • 4,354
  • 13
  • 73
  • 123

2 Answers2

3

In your curl command, you have used the -k/--insecure option to disable SSL certificate verification.

If you want to also disable SSL certificate verification, you can add verify=False to your requests.put call (See SSL Cert Verification).

But this is surely a bad idea from a security point of view. You must verify peer certificate by providing adequate root CA certificates.

math
  • 2,811
  • 3
  • 24
  • 29
0
requests.get(url, auth=('user', 'password'), verify=False)
rainy guan
  • 36
  • 3
  • 1
    While this might solve the original question, it's best to include a description so we know what is going on. – Tedinoz Mar 24 '20 at 04:35
  • 1
    Please don't post only code as an answer, but also include an explanation of what your code does and how it solves the problem of the question. Answers with an explanation are usually of higher quality and are more likely to attract upvotes. – Suraj Kumar Mar 24 '20 at 06:36