Loop through file and execute an api request
<p>I'm trying to write a web service in Python (fairly new to it). I have acces to an API that wants an url in a specific format:</p>

<pre><code>http://api.company-x.com/api/publickey/string/0/json
</code></pre>

<p>It is not a problem to perform a GET-request one by one but I would like to do it in a batch. So I have a text-file with strings in it. For example:</p>

<pre><code>string1,
string2,
string3,
</code></pre>

<p>I would like to write a Python-script that iterates through that file, makes it in the specific format, performs the requests and writes the responses of the batch to a new text-file. I've read the docs of requests and it mentioned adding parameters to your url but it doesn't do it in the specific format I need for this API.</p>

<p>My basic code so far without the loop looks like this:</p>

<pre><code>import requests
r = requests.get('http://api.company-x.com/api/publickey/string/0/json')

print(r.url)
data = r.text

text_file = open("file.txt", "w")
text_file.write(data)
text_file.close()
</code></pre>