试图显示来自URL的jpg图像,从以前对相同主题的问题的答案中复制精确的脚本,仍然出现错误

问题描述 投票:0回答:1
# Reading an excel file using Python
import xlrd
from urllib.request import urlopen
from PIL import Image
from skimage import io
from io import BytesIO

# Give the location of the file
loc = ("F://Documents//Bridges//URLs.xlsx")

# To open Workbook
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)

# input is requested and stored in a variable
row_start = input('Row Number =  ')

# convert user input into an integer
x = int(row_start)

# Find URL
image_url = sheet.cell_value(x,0)

# Print URl
print (image_url)

#Buffer image as described in earlier answer to same question
response = urlopen('image_url')
buf = BytesIO(response.read())
im = Image.open(buf)
a = io.Image(im)

#Display image    
io.imshow(a)
io.show()

# I get the following errors
#File "C:/Users/Wayne/PycharmProjects/untitled/URls2.py", line 29, in <module>
#   response = urlopen('image_url')
#  File "C:\Users\Wayne\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 222, 

在urlopen中#返回opener.open(URL,数据,超时)#文件“ C:\ Users \ Wayne \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ urllib \ request.py”,第509行,公开#req =请求(完整网址,数据)#文件“ C:\ Users \ Wayne \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ urllib \ request.py”,第328行,在init中#self.full_url =网址#文件“ C:\ Users \ Wayne \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ urllib \ request.py”,第354行,在full_url中#self._parse()#_parse中的文件“ C:\ Users \ Wayne \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ urllib \ request.py”,第383行#提高ValueError(“未知的URL类型:%r”%self.full_url)#ValueError:未知的网址类型:“ image_url”

excel image url jpeg display
1个回答
0
投票

我已经使用另一种更简单的方法解决了这个问题。请不要花时间尝试解决这一问题。我真的很感谢这个社区的帮助,并且不想滥用特权。

© www.soinside.com 2019 - 2024. All rights reserved.