Curl execution from pycharm

Hi,

I like to execute the curl command directly from pycharm without using requests module.

curl=‘curl -vk -L --user “username:password” --url “url_link”’

how can i execute above command from pycharm?
i tried subprocess but i cant able to get the access token from the response,
any other option?

Thanks!!

Hello,

I am guessing that you mean you want to execute the program curl from your python program. Pycharm is just an environment for developing python programs, not something we discuss in these forums.

Why you do not want to use requests? Normally it is faster, safer and easier to use a native library compared to an external program. There is also HTTP support right in the standard library: urllib — URL handling modules — Python 3.12.1 documentation

If you need some very specific curl behaviour, there is a python interface for libcurl: http://pycurl.io/

How can anyone help you without necessary details?

  1. Show runnable part of your code and describe where is the problem. (replace your sensitive data)
  2. Show how is the token stored in the response and how your curl command shows it.

Put any code, commands and their output between triple backticks to keep the original form of the text:

```
your text here
```

Hi,
Thanks for your reply.
First, we tried request module only but the url is redirecting and cant able to carry forward username and password. so i’m thinking to execute the curl command directly from pycharm because the curl command is working from command prompt.

This should certainly be solvable with requests. See for example: Python Requests - authentication after redirect - Stack Overflow The method of automatically sending password to the followed redirects is insecure. Even curl has some measures against that but I do not know the details.

If you want to help with pycharm, then it is not for this forum. If you want help with your python code, provide the details as I wrote earlier.

ya i explored that url which you attached in see for example.
if you look at the end of the conversation, they concluded that

“The point of the HTTP 302 is to perform URL redirection . The response with 302 status code provides a redirecting URL on its header under location key, which is to be triggered by making another request . So, No , you cannot achieve what you are trying to, through a single request

None of HTTP clients (including curl) can follow redirects in a single request! That is given by the design how HTTP redirects work. Redirect following consists of individual HTTP requests.

yes you are correct, i got redirect url. i’m trying to pass the redirect url along with credentials but its not achievable.