0

I have a list with three hashes and the script should create HTTP request for each hash in the list and then save the file of the hash. for some reason, the script generates only one HTTP request and for this reason, I manage to download only one file instead of three.

all_hashes = ['07a3355f81f0dbd9f5a9a', 'e0f1d8jj3d613ad5ebda6d', 'dsafhghhhffdsfdd']
for hash in all_hashes:
    params = {'apikey': 'xxxxxxxxxxxxx', 'hash': (hash)}
    response = requests.get('https://www.test.com/file/download', params=params)
    downloaded_file = response.content

name = response.headers['x-goog-generation']

if response.status_code == 200:
        with open('%s.bin' % name, 'wb') as f:
                f.write(response.content)

1 Answer 1

1

your response checking and saving code should also be in the loop e.g

all_hashes = ['07a3355f81f0dbd9f5a9a', 'e0f1d8jj3d613ad5ebda6d', 'dsafhghhhffdsfdd']
for hash in all_hashes:
    params = {'apikey': 'xxxxxxxxxxxxx', 'hash': (hash)}
    response = requests.get('https://www.test.com/file/download', params=params)
    downloaded_file = response.content

    name = response.headers['x-goog-generation']

    if response.status_code == 200:
            with open('%s.bin' % name, 'wb') as f:
                    f.write(response.content)

currently you response is the last request since your code is executed after the loop is finished.

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

Comments

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.