I need to send a text file to the address https://buscamedsenai-production.up.railway.app/ on the Railway server (https://railway.app/) so that an application written in Python can read it.
import requests
local_file_path = 'D:/teste.txt'
remote_url = 'https://buscamedsenai-production.up.railway.app/'
#local_file_path = 'caminho/para/seu/arquivo.txt' # Substitua pelo caminho do seu arquivo local
#remote_url = 'http://exemplo.com/upload' # Substitua pela URL do servidor remoto
try:
with open(local_file_path, 'rb') as file:
files = {'file': file}
response = requests.post(remote_url, files=files)
if response.status_code == 200:
print("Arquivo enviado com sucesso para o servidor remoto.")
else:
print(f"Erro ao enviar o arquivo. Código de resposta: {response.status_code}")
except FileNotFoundError:
print("Arquivo não encontrado. Verifique o caminho fornecido.")
except requests.RequestException as e:
print(f"Erro de requisição: {e}")