Created
July 19, 2023 11:52
-
-
Save oleg-agapov/f0fe8ab301a4062686d4acc50cfa2b4e to your computer and use it in GitHub Desktop.
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
import os | |
import asyncio | |
import contextlib | |
from pprint import pprint | |
from dotenv import load_dotenv | |
from netsuite import NetSuite, Config, TokenAuth | |
load_dotenv() # take environment variables from .env. | |
config = Config( | |
account="1234567_SB1", | |
auth=TokenAuth( | |
token_id=os.getenv("NETSUITE_TOKEN_ID"), | |
token_secret=os.getenv("NETSUITE_TOKEN_SECRET"), | |
consumer_key=os.getenv("NETSUITE_CONSUMER_KEY"), | |
consumer_secret=os.getenv("NETSUITE_CONSUMER_SECRET"), | |
), | |
) | |
ns = NetSuite(config) | |
## Monkeypatch httpx module so it is not asking for SSL certificate | |
@contextlib.contextmanager | |
def no_ssl_verification(): | |
"""Context manager to disable SSL verification on httpx AsyncClient """ | |
import httpx | |
# Save original Client constructor | |
AsyncClient = httpx.AsyncClient | |
# Disable SSL verification | |
httpx.AsyncClient = lambda *args, **kwargs: AsyncClient(*args, verify=False, **kwargs) | |
# Yield control to the caller | |
yield | |
# Restore original verify value | |
httpx.AsyncClient = AsyncClient | |
async def async_main(): | |
rest_api_results = await ns.rest_api.get("/record/v1/customer") | |
pprint(rest_api_results) | |
if __name__ == "__main__": | |
with no_ssl_verification(): | |
# everything in this context will be called with no SSL verification | |
# e.g. httpx.AsyncClient(..., verify=False) | |
asyncio.run(async_main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment