用于python请求的crtauth身份验证插件。

requests-crtauth的Python项目详细描述


请求crtauth

在[python请求](http://www.python-requests.org/)中支持[crtauth身份验证](https://github.com/spotify/crtauth)的插件。

用法

请求crtauth用作python请求的身份验证插件。有关详细信息,请参阅[身份验证文档](http://www.python-requests.org/en/latest/user/authentication/)。可以为httpcrtauth的新实例提供以下参数: ` username: User to authenticate as. Defaults to $USER. private_key: A PEM encoded private key string. Overrides signer. signer: A crtauth SigningPlug instance. Defaults to using the SSH agent (AgentSigner). version: Integer version of the crtauth protocol. Defaults to version 1. `

这里有一个例子。 `python In [1]: import requests, requests_crtauth, json, logging In [2]: logging.basicConfig(level=logging.DEBUG) In [3]: session = requests.Session() # HttpCrtAuth() will default to authenticating with your $USER env variable and a key from your SSH agent. # To specify an explicit key: requests_crtauth.HttpCrtAuth(username='negz',private_key='key data as a string') In [4]: session.auth = requests_crtauth.HttpCrtAuth() In [5]: data = json.dumps({'comment':'I\'m a comment!'}) In [6]: headers = {'content-type': 'application/json; charset=utf-8'} In [7]: response = session.put('https://db.spotify.net/v1/things/yomaris', data=data, headers=headers) INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): db.spotify.net DEBUG:requests.packages.urllib3.connectionpool:"PUT /v1/things/yomaris HTTP/1.1" 401 12 DEBUG:root:Sending challenge request DEBUG:requests.packages.urllib3.connectionpool:"HEAD /_auth HTTP/1.1" 200 0 DEBUG:root:Sending response to challenge REDACTED DEBUG:requests.packages.urllib3.connectionpool:"HEAD /_auth HTTP/1.1" 200 0 DEBUG:root:Stored CHAP token REDACTED DEBUG:root:Using newly stored CHAP token. DEBUG:requests.packages.urllib3.connectionpool:"PUT /v1/things/yomaris HTTP/1.1" 200 None In [8]: response.ok Out[8]: True `

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java动态地将圆添加到Arraylist   什么是好的“错误检查”模式(Java)?   java是我们可以在应用程序中使用的云服务,它需要存储最大大小为5MB的小文件   JavaGooglePhotosAPI是静态内容上传项目的永久url   java AES密钥存储   java文件正在下载,但没有任何内容   每次循环迭代和threadsleep的java日志记录都是不好的做法?   java不会切换到另一个。单击submit时使用jsp。春季mvc   java我很难从我的maclaurin系列中获得sin x的准确输出   java使用类似的<Object>?   需要java Hibernate映射吗?   java如何在https和客户端证书请求后面生成web服务代理   java如何通过注释有条件地使用自定义JsonSerializer   java如何在html页面和Restful WebResource方法之间实现JaxB?   读取文件Libgdx Android时发生java错误   java如何在处理主活动之前从另一个方法中获取值?   java在一个SQLquery中使用多个语句,还是使用批处理?