Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3
- import sys
- import traceback
- import json
- import socket
- import requests
- import PySimpleGUIQt as sg
- def report_error(e, url=None):
- tb = traceback.format_exc()
- if not internet() or url is None:
- sg.PopupScrolled(f'The following error occured:\n{tb}')
- sys.exit(1)
- data = json.dumps([sys.platform, sys.version, tb])
- p = sg.PopupScrolled(f'The following error has occured:\n{tb}\nWould you like to report this error?', yes_no=True)
- if p == 'Yes':
- print(f'Sending post request to {url}')
- requests.post(url, data=data)
- else:
- print('User declined to report error')
- sys.exit(1)
- def internet(host="8.8.8.8", port=53, timeout=3):
- """
- Host: 8.8.8.8 (google-public-dns-a.google.com)
- OpenPort: 53/tcp
- Service: domain (DNS/TCP)
- """
- try:
- socket.setdefaulttimeout(timeout)
- socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
- return True
- except Exception as e:
- return False
- if __name__ == '__main__':
- try:
- print(f)
- except Exception as e:
- report_error(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement