0

At a certain point in the execution of my Python script, I want to call cURL on the Windows command line, like so:

import subprocess
subprocess.call('curl', shell=True)

But I get this error:

'curl' is not recognized as an internal or external command, operable program or batch file.

Same thing happens if I use the full path:

subprocess.call('C:\\Windows\\System32\\curl.exe', shell=True)

'curl' is not recognized as an internal or external command, operable program or batch file.

Yet, if I simply open my Windows command prompt and type in 'curl', it works:

curl: try 'curl --help' for more information

Why?

(curl is in my Environment Variables, and my Visual C++ Redistributables are up-to-date. I am using Windows 10 Home on x64 machine.)

Thanks for your help!

  • check the path of curl, and you can run C:\\Windows\\System32\\curl.exe in your Windows command prompt – BertramLAU Mar 20 '19 at 05:37
  • 2
    Why do you want to call `curl` though? The Python `requests` library does pretty much everything `curl` does, but with much more programmatic control. – tripleee Mar 20 '19 at 05:44
  • Because I’m downloading a file via FTP instead of HTTP. I agree that ‘requests’ is wonderful, though. I’m looking into another Python package, ‘ftplib’, now.... – Steve Pfeiffer Mar 20 '19 at 21:14

1 Answers1

0

Turns out I don't need cURL after all. The second answer to this post helped me figure out how to download and save a file locally via FTP using Python's 'ftplib' package. Here's my final code:

from ftplib import FTP
with FTP('ftp.ncbi.nlm.nih.gov') as ftp:
    ftp.login()
    ftp.cwd('pubmed/baseline-2018-sample')
    # acronym: File To Be Downloaded
    FTBD = 'pubmed19n0004.xml.gz'
    # acronym: Where To Store Downloaded File
    WTSDF = open('C:/Users/S/Documents/this_project/pubmed19n0004.xml.gz', 'wb')
    ftp.retrbinary('RETR ' + FTBD, WTSDF.write, 1024)
    WTSDF.close()
    ftp.quit()