mirror of
https://github.com/Noettore/fattureCCSR.git
synced 2025-10-15 03:36:39 +02:00
Added try except block to check for connectivity errors
This commit is contained in:
@@ -6,13 +6,21 @@ import tempfile
|
|||||||
import openpyxl
|
import openpyxl
|
||||||
import PyPDF2
|
import PyPDF2
|
||||||
import wx
|
import wx
|
||||||
|
import requests
|
||||||
|
|
||||||
def download_input_file(parent):
|
def download_input_file(parent):
|
||||||
"""download input file"""
|
"""download input file"""
|
||||||
start_date = parent.start_date_picker.GetValue().Format("%d/%m/%Y")
|
start_date = parent.start_date_picker.GetValue().Format("%d/%m/%Y")
|
||||||
end_date = parent.end_date_picker.GetValue().Format("%d/%m/%Y")
|
end_date = parent.end_date_picker.GetValue().Format("%d/%m/%Y")
|
||||||
input_file_url = 'https://report.casadicurasanrossore.it:8443/reportserver?/STAT_FATTURATO_CTERZI&dataI='+start_date+'&dataF='+end_date+'&rs:Format=EXCELOPENXML'
|
input_file_url = 'https://report.casadicurasanrossore.it:8443/reportserver?/STAT_FATTURATO_CTERZI&dataI='+start_date+'&dataF='+end_date+'&rs:Format=EXCELOPENXML'
|
||||||
|
try:
|
||||||
downloaded_input_file = parent.session.get(input_file_url)
|
downloaded_input_file = parent.session.get(input_file_url)
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||||
|
parent.log_dialog.log_text.AppendText("ERRORE: impossibile connettersi al portale CCSR.")
|
||||||
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||||
|
wx.Yield()
|
||||||
|
return
|
||||||
if downloaded_input_file.status_code != 200:
|
if downloaded_input_file.status_code != 200:
|
||||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nControllare la connessione ad internet e l'operatività del portale CCSR. Code %d\n" % downloaded_input_file.status_code)
|
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nControllare la connessione ad internet e l'operatività del portale CCSR. Code %d\n" % downloaded_input_file.status_code)
|
||||||
@@ -73,6 +81,7 @@ def download_invoices(parent):
|
|||||||
downloaded_count = 0
|
downloaded_count = 0
|
||||||
|
|
||||||
for invoice_id, invoice in invoices.items():
|
for invoice_id, invoice in invoices.items():
|
||||||
|
try:
|
||||||
resp = parent.session.get(invoice["url"])
|
resp = parent.session.get(invoice["url"])
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
with open(tmp_dir+"/"+invoice_id+".pdf", "wb") as output_file:
|
with open(tmp_dir+"/"+invoice_id+".pdf", "wb") as output_file:
|
||||||
@@ -98,6 +107,12 @@ def download_invoices(parent):
|
|||||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||||
wx.Yield()
|
wx.Yield()
|
||||||
invoice["good"] = False
|
invoice["good"] = False
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||||
|
parent.log_dialog.log_text.AppendText("Errore: impossibile scaricare fattura %s: errore di connessione\n" % invoice_id)
|
||||||
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||||
|
wx.Yield()
|
||||||
|
invoice["good"] = False
|
||||||
|
|
||||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.BLACK, font=wx.Font(wx.FontInfo(8).Bold())))
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.BLACK, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||||
parent.log_dialog.log_text.AppendText("Download terminato.\n")
|
parent.log_dialog.log_text.AppendText("Download terminato.\n")
|
||||||
|
@@ -5,6 +5,7 @@ import sys
|
|||||||
import getopt
|
import getopt
|
||||||
import subprocess
|
import subprocess
|
||||||
import atexit
|
import atexit
|
||||||
|
from requests.models import RequestField
|
||||||
import wx
|
import wx
|
||||||
import wx.adv
|
import wx.adv
|
||||||
import requests
|
import requests
|
||||||
@@ -284,13 +285,17 @@ class LoginDialog(wx.Dialog):
|
|||||||
if self.username.GetValue() not in ("", None) and self.password.GetValue() not in ("", None):
|
if self.username.GetValue() not in ("", None) and self.password.GetValue() not in ("", None):
|
||||||
session = self.GetParent().session
|
session = self.GetParent().session
|
||||||
session.auth = requests_ntlm.HttpNtlmAuth("sr\\"+self.username.GetValue(), self.password.GetValue())
|
session.auth = requests_ntlm.HttpNtlmAuth("sr\\"+self.username.GetValue(), self.password.GetValue())
|
||||||
if session.get('https://report.casadicurasanrossore.it:8443/Reports/browse/').status_code == 200:
|
try:
|
||||||
|
login = session.get('https://report.casadicurasanrossore.it:8443/Reports/browse/')
|
||||||
|
if login.status_code == 200:
|
||||||
self.logged_in = True
|
self.logged_in = True
|
||||||
self.username.SetValue('')
|
self.username.SetValue('')
|
||||||
self.password.SetValue('')
|
self.password.SetValue('')
|
||||||
self.Close()
|
self.Close()
|
||||||
else:
|
else:
|
||||||
self.error_lbl.SetLabel("Errore: credenziali errate")
|
self.error_lbl.SetLabel("Errore: credenziali errate")
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
self.error_lbl.SetLabel("Errore: impossibile connettersi")
|
||||||
else:
|
else:
|
||||||
self.error_lbl.SetLabel("Errore: credenziali mancanti")
|
self.error_lbl.SetLabel("Errore: credenziali mancanti")
|
||||||
|
|
||||||
|
@@ -7,16 +7,24 @@ import tempfile
|
|||||||
import lxml.etree
|
import lxml.etree
|
||||||
import unidecode
|
import unidecode
|
||||||
import wx
|
import wx
|
||||||
|
import requests
|
||||||
|
|
||||||
def download_input_file(parent):
|
def download_input_file(parent):
|
||||||
"""download input file from CCSR SSRS web service"""
|
"""download input file from CCSR SSRS web service"""
|
||||||
start_date = parent.start_date_picker.GetValue().Format("%d/%m/%Y")
|
start_date = parent.start_date_picker.GetValue().Format("%d/%m/%Y")
|
||||||
end_date = parent.end_date_picker.GetValue().Format("%d/%m/%Y")
|
end_date = parent.end_date_picker.GetValue().Format("%d/%m/%Y")
|
||||||
input_file_url = 'https://report.casadicurasanrossore.it:8443/reportserver?/STAT_FATTURATO_CTERZI&dataI='+start_date+'&dataF='+end_date+'&rs:Format=XML'
|
input_file_url = 'https://report.casadicurasanrossore.it:8443/reportserver?/STAT_FATTURATO_CTERZI&dataI='+start_date+'&dataF='+end_date+'&rs:Format=XML'
|
||||||
|
try:
|
||||||
downloaded_input_file = parent.session.get(input_file_url)
|
downloaded_input_file = parent.session.get(input_file_url)
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||||
|
parent.log_dialog.log_text.AppendText("ERRORE: impossibile connettersi al portale CCSR.")
|
||||||
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||||
|
wx.Yield()
|
||||||
|
return None
|
||||||
if downloaded_input_file.status_code != 200:
|
if downloaded_input_file.status_code != 200:
|
||||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nControllare la connessione ad internet e l'operatività del portale CCSR. Code %d\n" % downloaded_input_file.status_code)
|
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nCode %d\n" % downloaded_input_file.status_code)
|
||||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||||
wx.Yield()
|
wx.Yield()
|
||||||
return None
|
return None
|
||||||
|
Reference in New Issue
Block a user