0

I have curl code recived a image file

curl -X GET -H 'Authorization: Bearer TOKENS' https://api.line.me/v2/bot/message/8595925133330/content -o image.png

how to get the file using python?

5
  • 3
    use requests? In particular, use requests.get(<URL>, ...). Commented Sep 19, 2018 at 12:49
  • 1
    already do that, but in case this use tokens Commented Sep 19, 2018 at 12:53
  • 2
    Take a look at docs.python-requests.org/en/master/user/quickstart/… - try that, and if you can't get it to work, show us what you've tried and someone should be able to help you. Commented Sep 19, 2018 at 12:57
  • 1
    @SpoonMeiser i do this r = requests.get(endpoint, headers=headers) how i get image file or json? Commented Sep 19, 2018 at 13:04
  • 2
    Put the actual code in your question, including what you set headers to. stackoverflow.com/help/how-to-ask Commented Sep 19, 2018 at 13:52

1 Answer 1

2
curl -X GET -H 'Authorization: Bearer TOKENS' https://api.line.me/v2/bot/message/8595925133330/content -o image.png

Comparable Python Script should be like below:

import requests
endpoint = "https://api.line.me/v2/bot/message/8595925133330/content"
headers = {"Authorization":"Bearer TOKENS"}

r = requests.post(endpoint,headers=headers)
open('image.png', 'wb').write(r.content)
Sign up to request clarification or add additional context in comments.

2 Comments

how about if this file not image file, i just change ext?
If it is binary, then you just change the ext., If it is text then you may change the write mode to 'w' and the ext. of the filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.