教训:
在调用request方法,实现模拟访问URL,返回状态码及响应结果时,由于自己写的某个文件命名为string.py,导致出现错误
from string import ascii_letters, digits, hexdigits
ImportError: cannot import name ‘ascii_letters‘
----------------------------------
# -*- coding:utf-8 -*-import urllib.request if __name__ == "__main__": r = urllib.request.urlopen(‘http://www.cnblogs.com/harbin-charles‘) print(r.status) print(r.reason) print(‘----------------------‘) print(r.headers) print(r.read().decode(‘utf-8‘))
时间: 2024-10-14 04:16:26