Мне сказали, что в адресе, который мы будем называть http://webservicehere.azurewebsites.net,, есть веб-служба REST. Моя задача - отправить строку размером до 64 КБ, чтобы веб-служба использовала ее и выдавала выходные данные. в успешном запросе он выдаст JSON, а в случае сбоя - сообщение об ошибке. У меня нет контроля над веб-сервисом.
Вот что я сделал до сих пор:
import json
import requests
from requests.exceptions import HTTPError
host = "http://httpbin.org/post"
host = "http://webservicehere.azurewebsites.net"
f = open('hard_code.xml', 'rb').read()
try:
response = requests.head(host,data=f)
response.encoding = "utf-8"
print("Encoding " + response.encoding)
#response = requests.get('https://api.github.com/search/repositories',
#params={'q': 'requests+language:python'})
response.raise_for_status()
print(response.status_code)
print(response.text)
if 'json' in response.headers.get('Content-Type'):
json_response = response.json()
print(json_response)
else:
print("Response not in JSon form")
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')