Skip to content

Commit 4f118a9

Browse files
committed
Update unittests on image download
Signed-off-by: Beat Buesser <[email protected]>
1 parent cbc47a8 commit 4f118a9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/attacks/test_steal_now_attack_later.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def collect_patches_from_images(detector, imgs):
7878

7979
# Download a sample image
8080
target = "https://farm2.staticflickr.com/1065/705706084_39a7f28fc9_z.jpg" # val2017/000000552842.jpg
81-
response = requests.get(target)
81+
headers = {
82+
"User-Agent": "Mozilla/5.0",
83+
"Referer": "https://www.flickr.com/"
84+
}
85+
response = requests.get(target, headers=headers)
8286
org_img = np.asarray(Image.open(BytesIO(response.content)).resize((640, 640)))
8387
x = np.stack([org_img.transpose((2, 0, 1)) / 255.0], axis=0).astype(np.float32)
8488

@@ -112,7 +116,7 @@ def collect_patches_from_images(detector, imgs):
112116
root_mscoco = "datasets"
113117
os.makedirs(root_mscoco, exist_ok=True)
114118
for idx, img_url in enumerate(list_url):
115-
response = requests.get(img_url)
119+
response = requests.get(img_url, headers=headers)
116120
with open(f"{root_mscoco}/{idx:03d}.jpg", "wb") as f:
117121
f.write(response.content)
118122
time.sleep(0.5)

0 commit comments

Comments
 (0)