我在qr_image = urllib2.urlopen(url).read()
收到此错误。我已经完成了与此here和here类似的所有问题。这些问题的答案表明存在代理连接问题。但是,我没有使用任何代理。我可能会犯一个简单的错误,但我完全被困在这里。
我已经清除了我之前在internet options>connections>LAN settings
中使用的代理设置。我还清除了http_proxy
ans https_proxy
个环境变量。
编辑:我之前使用的是代理连接,但现在已切换到拨号调制解调器。
import urllib2
import urllib
import gspread
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
w = 420
gc = gspread.login('panxxxxxx@gmail.com', 'xxxxxxxx')
wks = gc.open("Spreadsheet").sheet1 # "Spreadsheet" is the name of the Google Spreadsheet made in the account
val = wks.acell('A1').value
print val
# print len(wks.row_values(1))
list_of_lists = wks.get_all_values()
print list_of_lists
url = "https://api.qrserver.com/v1/create-qr-code?data=BEGIN%3AVCARD%0AVERSION%3A2.1%0AFN%3APraveen+Sridhar%0AN%3A%3BPraveen+Sridhar%0ATEL%3BHOME%3BVOICE%3A9544344104%0AEMAIL%3BHOME%3BINTERNET%3Aprvn431%40gmail.com%0AEND%3AVCARD%0A&size=220x220&margin=0"
for i in range(5):
idi = list_of_lists[i][0]
name = list_of_lists[i][1]
name_url = urllib.quote_plus(list_of_lists[i][1]) # url encoded name for api call
email = urllib.quote_plus(list_of_lists[i][2])
number = urllib.quote_plus(list_of_lists[i][3])
url = "https://api.qrserver.com/v1/create-qr-code/?data=BEGIN%3AVCARD%0AVERSION%3A2.1%0AFN%3A" + name_url + "%0AN%3A%3B" +\
name_url + "%0ATEL%3BHOME%3BVOICE%3A" + number + "%0AEMAIL%3BHOME%3BINTERNET%3A" +\
email + "%0AEND%3AVCARD%0A&size=50x50"
qr_image = urllib2.urlopen(url).read()
name_qr = name + ".png"
outfile = open(name_qr, 'wb')
outfile.write(qr_image)
outfile.close()
qr = Image.open(name_qr)
qr.thumbnail((120, 120))
thid = Image.open("tinkerhub_card.png") # Blank ID Card over which the QR code has to be placed
thid_new = Image.new('RGB', (420, 680))
thid_new.paste(thid, (0, 0))
thid_new.paste(qr, (150, 220))
id_usr_font = ImageFont.truetype("resources/OpenSans-Regular.ttf", 25)
id_usr = ImageDraw.Draw(thid_new)
w1, h1 = id_usr_font.getsize(idi)
id_usr = id_usr.text(((w - w1) / 2, 150), idi, (0, 0, 0), font=id_usr_font)
name_usr_font = ImageFont.truetype("resources/OpenSans-Regular.ttf", 30)
name_usr = ImageDraw.Draw(thid_new)
name_usr = name_usr.text((90, 365), name, (0, 0, 0), font=name_usr_font)
thid_new.show()
回溯
Traceback (most recent call last):
File "C:/Users/Harshil/Downloads/id-card-tinkerhub.py", line 41, in <module>
qr_image = urllib2.urlopen(url).read()
File "C:\Anaconda\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Anaconda\lib\urllib2.py", line 431, in open
response = self._open(req, data)
File "C:\Anaconda\lib\urllib2.py", line 449, in _open
'_open', req)
File "C:\Anaconda\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Anaconda\lib\urllib2.py", line 1240, in https_open
context=self._context)
File "C:\Anaconda\lib\urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>
Process finished with exit code 1