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