1
jpg의 URL이 진짜인지 확인하려고합니다.파이썬에서 소켓 오류를 잡는 방법?
import httplib
def exists(site, path):
conn = httplib.HTTPConnection(site)
conn.request('HEAD', path)
response = conn.getresponse()
conn.close()
return response.status == 200
print exists('uploads1.wikiart.org',
'/images/vincent-van-gogh/vincent-s-bedroom-in-arles-1889.jpg')
을하지만 내가 존재하지 않는 URL로 보내는 경우, 'uploads1111.wikiart.org',
처럼 말한다 소켓 오류 얻을 :
socket.error: [Errno 10060] A connection attempt failed
because the connected party did not properly respond after a period of time
를이 코드는 JPG가있는 경우 True
를 반환 작동 답변을 검색하여 errno
모듈과 관련이 있지만 해당 코드를 성공적으로 적용 할 수 없습니다. 어떤 소켓 오류라도 잡으려고하고 있는데 False
이 있으면이를 반환하려고합니다. 내 자신의 질문에
왜 그냥'socket.error'를 잡을 수없는 이유는 무엇입니까? –
고마워, 그거 쉽지. –