我正在尝试调整条形码输出的大小
import barcode
from barcode.writer import ImageWriter
bar_class = barcode.get_barcode_class('code128')
barcode = '1234567890'
writer=ImageWriter()
writer.set_options({module_width:2, module_height:2})
code128 = bar_class(barcode, writer)
code128.save('filename')
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'module_width' is not defined
Run Code Online (Sandbox Code Playgroud)
我真的不明白如何使用这里找到的文档:https ://pythonhosted.org/pyBarcode/writers/index.html
我正在尝试下载PDF,但是我收到以下错误:HTTP错误403:禁止
我知道服务器因任何原因都在阻塞,但我似乎无法找到解决方案.
import urllib.request
import urllib.parse
import requests
def download_pdf(url):
full_name = "Test.pdf"
urllib.request.urlretrieve(url, full_name)
try:
url = ('http://papers.xtremepapers.com/CIE/Cambridge%20IGCSE/Mathematics%20(0580)/0580_s03_qp_1.pdf')
print('initialized')
hdr = {}
hdr = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36',
'Content-Length': '136963',
}
print('HDR recieved')
req = urllib.request.Request(url, headers=hdr)
print('Header sent')
resp = urllib.request.urlopen(req)
print('Request sent')
respData = resp.read()
download_pdf(url)
print('Complete')
except Exception as e:
print(str(e))
Run Code Online (Sandbox Code Playgroud)