Skip to content

Commit

Permalink
Fix SSL issue
Browse files Browse the repository at this point in the history
  • Loading branch information
abelfodil committed Dec 9, 2024
1 parent d2ee9c1 commit bb3b3f7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/executable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.13
python-version: 3.12
- run: python -m pip install -r requirements.txt
- run: python -m PyInstaller --onefile --noconsole randwall
- uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions connection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from urllib.request import urlopen, Request
from http_client import get
from log import get_logger
from time import sleep

logger = get_logger(__name__)

def _is_connected():
urlopen(Request("https://1.1.1.1", headers={"User-Agent": "randwall/1.0"}))
get("https://1.1.1.1")
try:
return True
except:
Expand Down
10 changes: 10 additions & 0 deletions http_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ssl
import certifi
from urllib.request import urlopen, Request


def get(*args, **kwargs):
return urlopen(
Request(*args, **kwargs, method="GET", headers={"User-Agent": "randwall/1.0"}),
context=ssl.create_default_context(cafile=certifi.where()),
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
certifi
platformdirs==4.3.6
pyinstaller==6.11.1
watchfiles==1.0.0
7 changes: 4 additions & 3 deletions wallpaper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import platform
import os

from http_client import get
from log import get_logger
from urllib.request import urlopen, Request
from urllib.parse import urlencode
from config import config
import subprocess
Expand Down Expand Up @@ -89,7 +90,7 @@ def _get_random_wallpaper():
logger.info(f"Fetching random wallpaper from https://wallhaven.cc")

try:
with urlopen(Request(api_url + urlencode(params), headers={"User-Agent": "randwall/1.0"})) as f:
with get(api_url + urlencode(params)) as f:
response = f.read().decode("utf-8")
data = json.loads(response)
image_data = data["data"][0]
Expand All @@ -110,7 +111,7 @@ def _download_wallpaper(wallpaper):
logger.info(f"Downloading {wallpaper['url']} at {image_path}")

try:
with urlopen(Request(wallpaper["path"], headers={"User-Agent": "randwall/1.0"})) as f:
with get(wallpaper["path"]) as f:
image = f.read()
except:
return
Expand Down

0 comments on commit bb3b3f7

Please sign in to comment.