【问题标题】:pycurl: RETURNTRANSFER option doesn't existpycurl:RETURNTRANSFER 选项不存在
【发布时间】:2009-05-16 17:23:13
【问题描述】:

我正在使用 pycurl 访问 JSON Web API,但是当我尝试使用以下内容时:

ocurl.setopt(pycurl.URL, gaurl)       # host + endpoint
ocurl.setopt(pycurl.RETURNTRANSFER, 1)
ocurl.setopt(pycurl.HTTPHEADER, gaheader) # Send extra headers
ocurl.setopt(pycurl.CUSTOMREQUEST, "POST") # HTTP POST req
ocurl.setopt(pycurl.CONNECTTIMEOUT, 2)

并执行脚本,它失败了。

File "getdata.py", line 46, in apicall
ocurl.setopt(pycurl.RETURNTRANSFER, 1)
AttributeError: 'module' object has no attribute 'RETURNTRANSFER'

我不知道发生了什么,以及为什么 RETURNTRANSFER 似乎不存在,而所有其他选项都存在。

【问题讨论】:

    标签: python curl libcurl pycurl attributeerror


    【解决方案1】:

    手册显示用法为something like this

    >>> import pycurl
    >>> import StringIO
    >>> b = StringIO.StringIO()
    >>> conn = pycurl.Curl()
    >>> conn.setopt(pycurl.URL, 'http://www.example.org')
    >>> conn.setopt(pycurl.WRITEFUNCTION, b.write)
    >>> conn.perform()
    >>> print b.getvalue()
    <HTML>
    <HEAD>
      <TITLE>Example Web Page</TITLE>
    </HEAD>
    <body>
    <p>You have reached this web page by typing &quot;example.com&quot;,
    &quot;example.net&quot;,
      or &quot;example.org&quot; into your web browser.</p>
    <p>These domain names are reserved for use in documentation and are not availabl
    e
      for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
    
      2606</a>, Section 3.</p>
    </BODY>
    </HTML>
    

    似乎有点迂回,但我不是 PycURL 的忠实粉丝...

    【讨论】:

    • 是的,效果很好。我想知道他们为什么不一开始就实施 RETURNTRANSFER。
    【解决方案2】:

    CURLOPT_RETURNTRANSFER 不是 libcurl 选项,但它在 PHP/CURL 绑定中提供

    【讨论】:

      【解决方案3】:

      您是否尝试过执行print dir(pycurl) 并查看该选项是否存在于属性列表中?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-29
        • 2021-08-18
        • 2020-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-03
        相关资源
        最近更新 更多