简体   繁体   English

将示例卷曲到pycurl

[英]curl example to pycurl

Here is my command 这是我的命令

curl -i -H 'X-Storage-User:12345:12345' -H 'X-Storage-Pass:new1234' https://ssproxy.ucloudbiz.olleh.com/auth/v1.0

Result 结果

HTTP/1.1 200 OK
Date: Fri, 08 Jan 2016 05:49:06 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 126
Connection: close
X-Auth-Token-Expires: 51114
X-Auth-Token: AUTH_tkdfefef8dfsfsefsf
X-Storage-Token: AUTH_tkdfefef8dfsfsefsf
X-Storage-Url: https://ssproxy.ucloudbiz.olleh.com/v1/AUTH_3xxsdff_sdfwef_sdfwf
X-Trans-Id: tx76sdsefwfwwt

How do I convert it to pycurl? 如何将其转换为pycurl?

Thank you in advance. 先感谢您。

Here is the corrisponding command in pycurl written in Python 3: 这是用Python 3编写的pycurl中的相应命令:

import pycurl
import sys

def bodycb(buf):
    import sys
    sys.stdout.buffer.write(buf)

def headercb(buf):
    import sys
    sys.stdout.buffer.write(buf)

headers = ['X-Storage-User:12345:12345', 'X-Storage-Pass:new1234']

pycurl_connect = pycurl.Curl()
pycurl_connect.setopt(pycurl.URL, 'https://ssproxy.ucloudbiz.olleh.com/auth/v1.0')
pycurl_connect.setopt(pycurl.HTTPHEADER, headers)
pycurl_connect.setopt(pycurl.WRITEFUNCTION, bodycb)
pycurl_connect.setopt(pycurl.HEADERFUNCTION, headercb)
pycurl_connect.perform() 

You need to pass in your headers in a list using pycurl.HTTPHEADER. 您需要使用pycurl.HTTPHEADER在列表中传递标头。 The headercb and bodycb functions are just callbacks to print the responses headers and body to the console. headercb和bodycb函数只是将响应头和主体打印到控制台的回调。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM