• 1000 Но, к сожалению, он подключается только к одному URL-адресу и выдает исключение. Можно ли подключить вторичный, если первичный URL не работает? может кто-нибудь помочь мне решить эту проблему?
code:
import os
import requests
import logging
retry_count = 2
timeout = 10
class consumer():
def send_request(self, retry=retry_count, **kwargs):
primaryURL = 'www.w3schools.com/xml/' #sample link
secondaryURL = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL' #sample link
for i in range(retry):
headers = {'content-type': 'text/xml'}
try:
headers = {'content-type': 'text/xml'}
if primaryURL:
response = requests.post(primaryURL, data=body, headers=headers, **kwargs)
elif secondaryURL:
response = requests.post(secondaryURL, data=body, headers=headers)
break
except TimeoutError as e:
print("request post time out for URL")
continue
except Exception as e:
logging.error(e)
def main(self):
self.send_request()
if __name__ == "__main__":
consumer = consumer()
consumer.main()