32 lines
678 B
Python
32 lines
678 B
Python
import requests
|
|
from pathlib import Path
|
|
from tokopedia_config import Config
|
|
|
|
class api():
|
|
config = Config().get()
|
|
|
|
def post(self, url, payload):
|
|
try:
|
|
response = requests.post(url, payload)
|
|
return response.json()
|
|
except:
|
|
return []
|
|
|
|
def postProxy(self, url, payload, headers):
|
|
path = Path.cwd()
|
|
proxyUrl = self.config.get('proxy_url')
|
|
# print(data)
|
|
try:
|
|
response = requests.post(url,
|
|
data=payload,
|
|
headers=headers,
|
|
proxies={
|
|
"http": proxyUrl,
|
|
"https": proxyUrl,
|
|
},
|
|
verify=f'{path}/zyte-proxy-ca.crt'
|
|
)
|
|
return response.json()
|
|
except:
|
|
return []
|