0
파이썬 3.5의 http://learncodethehardway.org/words.txt URL에 액세스하려고하는데 아래 코드를 시도했지만 403 HTTP 오류가 발생했습니다. 어떻게 이것을 피하려면 headers
을 구성해야합니까?요청에 금지 된 (403) 오류, Python 3.5의 urlopen
import urllib.request
url = "http://learncodethehardway.org/words.txt"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
req = urllib.request.Request(url, None, headers=hdr)
html = urllib.request.urlopen(req)
print (html.read())
가 왜 403 오류가 발생한다? –
코드를 그대로 실행했는데 403없이 응답을 받았습니다. –