Skip to content

Commit

Permalink
fix json decode error
Browse files Browse the repository at this point in the history
  • Loading branch information
jakbin committed Jan 15, 2024
1 parent 7de2b55 commit 0d2ddc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion anonupload/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__= "1.2.0"
__version__= "1.2.1"

from .main import download, downloads, upload, changefile_and_upload
34 changes: 19 additions & 15 deletions anonupload/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
import requests_toolbelt
import urllib.parse as urlparse
from requests.exceptions import MissingSchema
from requests.exceptions import MissingSchema, JSONDecodeError
from requests import get, ConnectionError, head

from anonupload import __version__
Expand Down Expand Up @@ -54,20 +54,24 @@ def upload(filename):
headers={"Content-Type": monitor.content_type},
)

resp = json.loads(r.text)
if resp['status']:
# urlshort = resp['data']['file']['url']['short']
urllong = resp['data']['file']['url']['full']
print(f'[SUCCESS]: Your file has been succesfully uploaded:\nFull URL: {urllong}')
with open('urls.txt', 'a+') as f:
f.write(f"{urllong}\n")
print('url saved in urls.txt file')
return urllong
else:
message = resp['error']['message']
errtype = resp['error']['type']
print(f'[ERROR]: {message}\n{errtype}')
return message, errtype
try:
resp = json.loads(r.text)

if resp['status']:
# urlshort = resp['data']['file']['url']['short']
urllong = resp['data']['file']['url']['full']
print(f'[SUCCESS]: Your file has been succesfully uploaded:\nFull URL: {urllong}')
with open('urls.txt', 'a+') as f:
f.write(f"{urllong}\n")
print('url saved in urls.txt file')
return urllong
else:
message = resp['error']['message']
errtype = resp['error']['type']
print(f'[ERROR]: {message}\n{errtype}')
return message, errtype
except JSONDecodeError:
print(r.text)

def changefile_and_upload(filenames: List[str]):
for filename in filenames:
Expand Down

0 comments on commit 0d2ddc7

Please sign in to comment.