AttributeError: у объекта 'cStringIO.StringO' нет атрибута 'getValue' - PullRequest
0 голосов
/ 23 июня 2018

Я новичок в python (но не в php) и провожу некоторый тест, чтобы изучить его самостоятельно.

Когда я запускаю код с URL-адресами в массиве, я получаю эту ошибку:

print req[1].getValue()
AttributeError: 'cStringIO.StringO' object has no attribute 'getValue'

Когда я проверяю атрибуты, я вижу:

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

Когда я проверяю

req.getValue ()

Я получаю это:

print req.getValue()
AttributeError: 'tuple' object has no attribute 'getValue'

Что я делаю не так?Код найден здесь: https://fragmentsofcode.wordpress.com/2011/01/22/pycurl-curlmulti-example/

    #urls = [...]  # list of urls
    # reqs: List of individual requests.
    # Each list element will be a 3-tuple of url (string), response string buffer
    # (cStringIO.StringIO), and request handle (pycurl.Curl object).
    reqs = []

    # Build multi-request object.
    m = pycurl.CurlMulti()
    for url in urls:
        response = StringIO()
        handle = pycurl.Curl()
        handle.setopt(pycurl.URL, url)
        handle.setopt(pycurl.WRITEFUNCTION, response.write)
        req = (url, response, handle)
        # Note that the handle must be added to the multi object
        # by reference to the req tuple (threading?).
        m.add_handle(req[2])
        reqs.append(req)

    # Perform multi-request.
    # This code copied from pycurl docs, modified to explicitly
    # set num_handles before the outer while loop.
    SELECT_TIMEOUT = 1.0
    num_handles = len(reqs)
    while num_handles:
        ret = m.select(SELECT_TIMEOUT)
        if ret == -1:
            continue
        while 1:
            ret, num_handles = m.perform()
            if ret != pycurl.E_CALL_MULTI_PERFORM:
                break

    # print response.getValue()

    for req in reqs:
        # req[1].getvalue() contains response content
        # print dir(req)
        print req[1].getValue()
...