This code is to get some images from the URL stored in the excel file. The code is also to save them but when I ran the code, I got this error "HTTPError: HTTP Error 400: Bad Request". What can I do to solve the problem?
import pandas as pd
import urllib.request
def url_to_jpg(i, url, file_Path):
filename = 'image_{}.jpg'.format(i)
full_path = '{}{}'.format(file_Path, filename)
urllib.request.urlretrieve(url, full_path)
print('{} saved.'.format(filename))
return None
File_Name = 'Cooler_URL_2.xlsx'
File_Path = 'images/'
#reading the file as pandas dataframe
urls = pd.read_excel(File_Name)
#save file as directory
for i, url in enumerate(url_values):
url_to_jpg(i, url[0], File_Path)
As mentioned, the most common cause of a 400 Bad Request Error is simply inputting an incorrect URL. Domain names (eg abc.com) are case-insensitive, meaning that this mixed case link to ABC.COM works just as well as the normal, lowercase version of abc.com.
下面这行for i, url in enumerate(url_values): url_to_jpg(i, url[0], File_Path)
被替换为for i, url in enumerate(url_values): url_to_jpg(i, url, File_Path)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.