import requests
# URL of the avatar image
avatar_url = "url.bin"
# Custom headers
headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Mobile Safari/537.36",
"Accept": "*/*",
}
# Send a GET request to the avatar URL with headers
response = requests.get(avatar_url, headers=headers, stream=True)
print(f"Content-Type: {response.headers.get('Content-Type')}")
# Check if the request was successful
if response.status_code == 200:
# Save the image to a file
with open("avatar_VGA23498.bin", "wb") as file:
file.write(response.content)
print("Avatar downloaded successfully.")
else:
print(f"Failed to download avatar. Status code: {response.status_code}")
I want to get image from the URL and save it in local files. But the status_code response is 403. If I click on the URL link. It shows:
<Error>
<script/>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>96KTSVWPQR3YZHJW</RequestId>
<HostId>WbjxwXXuo92OUkd+0VP8Pg1rvm6vFWg1s7ciyyxlfr/O4S62Q77yCHJzRb1YnJlIqvlpkP+LduV2wQBUxsDsOQ== </HostId>
</Error>
How can I get an image from url.bin ?
2