79509181

Date: 2025-03-14 13:20:53
Score: 1
Natty:
Report link

Thanks to Sona I solved the issue. In case somebody is facing the same problem and has to debug, here it is my full code, copyng Sona and other posts.

import requests
from requests.auth import HTTPBasicAuth
import logging
import contextlib
from http.client import HTTPConnection

#https://stackoverflow.com/questions/16337511/log-all-requests-from-the-python-requests-module
# FOR DEBUGGING
def debug_requests_on():
    '''Switches on logging of the requests module.'''
    HTTPConnection.debuglevel = 1

    logging.basicConfig()
    logging.getLogger().setLevel(logging.DEBUG)
    requests_log = logging.getLogger("requests.packages.urllib3")
    requests_log.setLevel(logging.DEBUG)
    requests_log.propagate = True

def debug_requests_off():
    '''Switches off logging of the requests module, might be some side-effects'''
    HTTPConnection.debuglevel = 0

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.WARNING)
    root_logger.handlers = []
    requests_log = logging.getLogger("requests.packages.urllib3")
    requests_log.setLevel(logging.WARNING)
    requests_log.propagate = False

@contextlib.contextmanager
def debug_requests():
    '''Use with 'with'!'''
    debug_requests_on()
    yield
    debug_requests_off()

debug_requests_on()

#from Sona

files = {'flusso': ('lista.csv', open('here the file', 'rb'), 'text/plain')}

body, content_type = requests.models.RequestEncodingMixin._encode_files(files, {})

data = body
headers = {
    "Content-Type": content_type,
    'Content-Disposition': 'form-data; name="flusso"',
    'Content-Disposition': 'form-data; filename="lista.csv"',
    'Accept-Encoding': 'gzip,deflate',
    'User-Agent': '',
    'MIME-Version': '1.0',
    'Connection' : 'keep-alive',
}
r = requests.post(
    url,
    data=data,
    headers=headers,
    auth=HTTPBasicAuth('here the user', 'here the password')
)
if r.ok:
    print("Login: Success!")
    print(r.text)    
    print(r.status_code)
    print(r)
else:
    raise Exception("Errore. ", r.status_code)
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-2): I solved
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): facing the same problem
  • Low reputation (0.5):
Posted by: dario