import grequests with open("C:\\path\\urls.txt") as werewolves: array = [row.strip() for row in werewolves] params = {'a':'b', 'c':'d'} rs = [grequests.post(u, data=params) for u in array] for r in grequests.imap(rs, size=16) print(r[0].status_code, r[0].url)
TypeError: 'Response' object does not support indexing
def exception_handlerr(request, exception): print("Request failed", request.url) import grequests with open("C:\\path\\urls.txt") as werewolves: array = [row.strip() for row in werewolves] params = {'a':'b', 'c':'d'} rs = [grequests.post(u, data=params) for u in array] for r in grequests.map([rs], size=16, exception_handler=exception_handlerr) print(r[0].status_code, r[0].url)
def send(self, **kwargs): """ Prepares request based on parameter passed to constructor and optional ``kwargs```. Then sends request and saves response to :attr:`response` :returns: ``Response`` """ merged_kwargs = {} merged_kwargs.update(self.kwargs) merged_kwargs.update(kwargs) try: self.response = self.session.request(self.method, self.url, **merged_kwargs) except Exception as e: self.exception = e self.traceback = traceback.format_exc() return self
def exception_handlerr(request, exception): print("Request failed", request.url) # print(str(exception))
def exception_handlerr(request, exception): print("Request failed", request.url) import grequests with open("C:\\path\\urls.txt") as werewolves: array = [row.strip() for row in werewolves] params = {'a':'b', 'c':'d'} rs = [grequests.post(u, data=params) for u in array] for r in grequests.map([rs], size=16, exception_handler=exception_handlerr) print(r.status_code, r.url)
def exception_handlerr(request, exception): print("Request failed", request.url) import grequests with open("C:\\path\\urls.txt") as werewolves: array = [row.strip() for row in werewolves] rs = [grequests.get(u) for u in array] for r in grequests.map([rs], size=16, exception_handler=exception_handlerr) print(r.status_code, r.url)
Source: https://habr.com/ru/post/334970/
All Articles