我的代码和示例代码不同,跑不出来示例代码的3次计数打印效果,求牛爷爷指点思路。
这是示例的
import requests
from retrying import retry
class BaiDu:
def __init__(self):
self.url_ = "xxxx.com"
self.num_ = 0
@retry(stop_max_attempt_number=3)
def send_request(self):
self.num_ += 1
print(self.num_)
requests.get(self.url_)
def run(self):
try:
self.send_request()
except Exception as e:
print(e)
if __name__ == '__main__':
bd_obj = BaiDu() # 创建对象
bd_obj.run()
下面的是我的
import requests
from retrying import retry
class send_request_:
def __init__(self):
self.url_ = "986978.com"
self.num_ = 0
@retry(stop_max_attempt_number=3)
def send_request(self):
self.num_ += 1
print(self.num_)
try:
requests.get(self.url_)
response_ = requests.content.decode()
preint(response_)
except Exception as e:
print(e)
a = send_request_()
a.send_request
结果只有
Process finished with exit code 0

这是示例的
import requests
from retrying import retry
class BaiDu:
def __init__(self):
self.url_ = "xxxx.com"
self.num_ = 0
@retry(stop_max_attempt_number=3)
def send_request(self):
self.num_ += 1
print(self.num_)
requests.get(self.url_)
def run(self):
try:
self.send_request()
except Exception as e:
print(e)
if __name__ == '__main__':
bd_obj = BaiDu() # 创建对象
bd_obj.run()
下面的是我的
import requests
from retrying import retry
class send_request_:
def __init__(self):
self.url_ = "986978.com"
self.num_ = 0
@retry(stop_max_attempt_number=3)
def send_request(self):
self.num_ += 1
print(self.num_)
try:
requests.get(self.url_)
response_ = requests.content.decode()
preint(response_)
except Exception as e:
print(e)
a = send_request_()
a.send_request
结果只有
Process finished with exit code 0

