0

I have been trying to run this code,

import csv
import os

token = 'Bearer xxx"'

with open('uris.csv', 'r', newline = '',encoding = 'utf-8') as ifp:
    ir = csv.reader(ifp)

    for i, row in enumerate(ir):
        v = ('curl -X "POST" "https://api.spotify.com/v1/playlists/7miRhC7OZhQUvnP1ONghJm/tracks?uris=spotify%3Atrack%3A'+
            ', '.join(row)+
            '" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: '+
            token + '\n')
        os.system("gnome-terminal -e 'bash -c \""+v+"; sleep 10\" '")
        print(v)

which takes some spotify track uris from a csv and puts them into the curl that anyone can get from Spotify Api. This curl adds the specific track to my playlist. Then I open a new terminal and execute the curl. (the os.system command was found from open terminal run command python)

The problem is that when I execute this code with python3 code.py new terminals for each curl open but none curl is executed. The curls themselves are right. If I copy paste one curl and run it, the track is added to my playlist. Also if I run a curl separately, I get a response in the terminal which i don't get if I run curls through the code. The response is something like this:

{
  "snapshot_id" : "MTQxxx"
}

Thanks a lot.

1 Answer 1

1

Silly to ask, but why not just directly call curlOutput = os.system("curl [your concatenation]")?

Might just solve your issue.

Sign up to request clarification or add additional context in comments.

2 Comments

Dude...you just saved me!!! I am a total noob and I wasn't thinking clever. I thought i had to open a new terminal for each curl. Your way worked 100%. Thanks a lot!! (it's a shame my upvote isn't being desplayed cause i have less than 15 rep lol)
Glad to help. Sometimes we all over-engineer solutions, 'noobs' or not. Regarding the upvote, I think you can still checkmark the answer though.

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.