>  기사  >  백엔드 개발  >  기본 및 다이제스트 인증을 확인하는 Python pycurl 메소드

기본 및 다이제스트 인증을 확인하는 Python pycurl 메소드

不言
不言원래의
2018-05-02 13:48:112145검색

이 글에서는 Python pycurl에서 기본 인증과 다이제스트 인증을 검증하는 방법을 주로 소개하고 있으니 참고용으로 올려보겠습니다. 함께 살펴볼까요

소개

pycurl은 Python의 urllib와 유사하지만 pycurl은 libcurl의 패키지로 더 빠릅니다.

이 글은 pycurl 버전 7.43.0.1을 사용합니다.

Apache에서 기본 인증 구성

기본 비밀번호 파일 생성

htpasswd -bc passwd.basic test 123456

mod_auth_basic 활성화

LoadModule auth_basic_module modules/mod_auth_basic.so

특정 디렉터리로 구성

<Directory "D:/test/basic">
  AuthName "Basic Auth Dir"
  AuthType Basic
  AuthUserFile conf/passwd.basic
  require valid-user
</Directory>

아파치 다시 시작

Apache에서 다이제스트 인증 구성

다이제스트 비밀번호 파일 생성

htdigest -c passwd.digest "Digest Encrypt" test

mod_auth_digest

LoadModule auth_digest_module modules/mod_auth_digest.so

특정 디렉토리로 구성

<Directory "D:/test/digest">
  AuthType Digest
  AuthName "Digest Encrypt" # 要与密码的域一致
  AuthDigestProvider file
  AuthUserFile conf/passwd.digest
  require valid-user
</Directory>

Apache 다시 시작

확인 기본 인증

# -*- coding: utf-8 -*-
import pycurl
try:
  from io import BytesIO
except ImportError:
  from StringIO import StringIO as BytesIO
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, &#39;http://test/basic/&#39;)
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.HTTPAUTH, c.HTTPAUTH_BASIC)
c.setopt(c.USERNAME, &#39;test&#39;)
c.setopt(c.PASSWORD, &#39;123456&#39;)
c.perform()
print(&#39;Status: %d&#39; % c.getinfo(c.RESPONSE_CODE))
print(buffer.getvalue())
c.close()

인증된 다이제스트 인증

# -*- coding: utf-8 -*-
import pycurl
try:
  from io import BytesIO
except ImportError:
  from StringIO import StringIO as BytesIO
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, &#39;http://test/digest/&#39;)
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.HTTPAUTH, c.HTTPAUTH_DIGEST)
c.setopt(c.USERNAME, &#39;test&#39;)
c.setopt(c.PASSWORD, &#39;123456&#39;)
c.perform()
print(&#39;Status: %d&#39; % c.getinfo(c.RESPONSE_CODE))
print(buffer.getvalue())
c.close()


위 내용은 기본 및 다이제스트 인증을 확인하는 Python pycurl 메소드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.