-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preview output using labalary API
- Loading branch information
1 parent
d789d10
commit 14e9922
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import requests | ||
import os | ||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
# Wrappers around the requests for better error handling | ||
class Wrappers(): | ||
|
||
def post_request(self, post_data, path, headers): | ||
proxy_con = os.getenv('PROXY_CON') | ||
proxy_url = os.getenv('PROXY_URL') | ||
if proxy_con and proxy_url: | ||
proxies = {proxy_con: proxy_url} | ||
elif self.get_setting('PROXY_CON') != '' and self.get_setting('PROXY_URL') != '': | ||
proxies = {self.get_setting('PROXY_CON'): self.get_setting('PROXY_URL')} | ||
else: | ||
proxies = {} | ||
try: | ||
response = requests.post(path, | ||
proxies=proxies, | ||
data=post_data, | ||
timeout=5, | ||
headers=headers) | ||
except Exception as e: | ||
return (e.args) | ||
return (response) | ||
|
||
def get_request(self, path, headers): | ||
proxy_con = os.getenv('PROXY_CON') | ||
proxy_url = os.getenv('PROXY_URL') | ||
if proxy_con and proxy_url: | ||
proxies = {proxy_con: proxy_url} | ||
elif self.get_setting('PROXY_CON') != '' and self.get_setting('PROXY_URL') != '': | ||
proxies = {self.get_setting('PROXY_CON'): self.get_setting('PROXY_URL')} | ||
else: | ||
proxies = {} | ||
try: | ||
response = requests.get(path, | ||
proxies=proxies, | ||
timeout=5, | ||
headers=headers) | ||
except Exception as e: | ||
return (e.args) | ||
return (response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters