Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求和回调_Python_Python 3.x_Python Requests - Fatal编程技术网

Python请求和回调

Python请求和回调,python,python-3.x,python-requests,Python,Python 3.x,Python Requests,我遵循了grequests使用示例,但我试图添加一些进度反馈。已完成请求的百分比。我怎样才能做到这一点?我的意思是,我不知道在这种情况下如何实现计数器。我尝试过其他几个库,以及stackoverflow中的许多代码,但大多数都是针对Python2.7的,不适用于3.7。下面我附上引发错误的示例代码: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, inc

我遵循了grequests使用示例,但我试图添加一些进度反馈。已完成请求的百分比。我怎样才能做到这一点?我的意思是,我不知道在这种情况下如何实现计数器。我尝试过其他几个库,以及stackoverflow中的许多代码,但大多数都是针对Python2.7的,不适用于3.7。下面我附上引发错误的示例代码:

MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7.
代码

import grequests

filename = 'RemoteDir.exe'
url = f'https://rowerovsky.pl/{filename}'

URLS = [
    url
]

class FeedbackCounter:
    """Object to provide a feedback callback keeping track of total calls."""
    def __init__(self):
        self.counter = 0

    def feedback(self, r, **kwargs):
        self.counter += 1
        print("{0} fetched, {1} total.".format(r.url, self.counter))
        return r


fbc = FeedbackCounter()
rs = (grequests.get(u, callback=fbc.feedback) for u in URLS)
res = grequests.map(rs)