Why am I encountering OperationalError while using Python SDK netsuitesdk and how can I resolve it?

This topic was automatically generated from Slack. You can find the original thread here.

Some Python help needed over here.

I am getting this error when using this Python SDK netsuitesdk

These are my imports. What am I missing or doing wrong pls

**import** os
**import** itertools
**import** json
**import** requests
**import** asyncio
**from** netsuitesdk **import** NetSuiteConnection
**from** zeep.cache **import** SqliteCache #Added this when I traced the below error and thought it will help

OperationalError
unable to open database file

Traceback (most recent call last):

  File "/pipedream/dist/code/f222f9ca455306c0cbed46da9982c7d049bcea3154192d6a3033e26843961c17/code.py", line 60, in handler
    nc = retry_until_success()

  File "/pipedream/dist/code/f222f9ca455306c0cbed46da9982c7d049bcea3154192d6a3033e26843961c17/code.py", line 50, in retry_until_success
    result = retry_function()

  File "/pipedream/dist/code/f222f9ca455306c0cbed46da9982c7d049bcea3154192d6a3033e26843961c17/code.py", line 40, in retry_function
    result = connect_tba() #some_function_that_might_fail()

  File "/pipedream/dist/code/f222f9ca455306c0cbed46da9982c7d049bcea3154192d6a3033e26843961c17/code.py", line 28, in connect_tba
    nc = NetSuiteConnection(

  File "/pipedream/dist/python/netsuitesdk/connection.py", line 40, in __init__
    ns_client = NetSuiteClient(account=account, caching=caching, caching_timeout=caching_timeout,

  File "/pipedream/dist/python/netsuitesdk/internal/client.py", line 72, in __init__
    cache = SqliteCache(path=path, timeout=timeout)

  File "/pipedream/dist/python/zeep/cache.py", line 121, in __init__
    with self.db_connection() as conn:

  File "/var/lang/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)

  File "/pipedream/dist/python/zeep/cache.py", line 134, in db_connection
    connection = sqlite3.connect(

sqlite3.OperationalError: unable to open database file


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/nano-py/pipedream/worker.py", line 118, in execute
    user_retval = handler(pd)

  File "/pipedream/dist/code/f222f9ca455306c0cbed46da9982c7d049bcea3154192d6a3033e26843961c17/code.py", line 65, in handler
    nc = connect_tba()

  File "/pipedream/dist/code/f222f9ca455306c0cbed46da9982c7d049bcea3154192d6a3033e26843961c17/code.py", line 28, in connect_tba
    nc = NetSuiteConnection(

  File "/pipedream/dist/python/netsuitesdk/connection.py", line 40, in __init__
    ns_client = NetSuiteClient(account=account, caching=caching, caching_timeout=caching_timeout,

  File "/pipedream/dist/python/netsuitesdk/internal/client.py", line 72, in __init__
    cache = SqliteCache(path=path, timeout=timeout)

  File "/pipedream/dist/python/zeep/cache.py", line 121, in __init__
    with self.db_connection() as conn:

  File "/var/lang/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)

  File "/pipedream/dist/python/zeep/cache.py", line 134, in db_connection
    connection = sqlite3.connect(

sqlite3.OperationalError: unable to open database file

(createFileInNetSuite)

Thanks for the code & error trace, that’s very helpful to follow along with.

The error message states that it needs to read a database file:

unable to open database file 

I’m not sure which package in particular it’s referencing to, but you might need to download a database file to /tmp and pass that path as an argument to this module’s constructor.

So it works when I run this code step within the workflow… and sometimes when the workflow it triggered,

Other times, it doesnt

If it fails, and then I go into the workflow and run the step, it runs flawlessly

But most times, when the workflow is triggered, it encounters….

https://docs.python-zeep.org/en/master/transport.html#transport-caching

I think its referring to a Sqllitecache

def __init__(self, account, consumer_key, consumer_secret, token_key, token_secret,
caching=True, caching_timeout=2592000, caching_path=None,
search_body_fields_only=True, page_size: int = 100):
ns_client = NetSuiteClient(account=account, caching=caching, caching_timeout=caching_timeout,
caching_path=caching_path, search_body_fields_only=search_body_fields_only,
page_size=page_size)

This is the code within the SDK doing the connection netsuite-sdk-py/netsuitesdk/internal/client.py at master · fylein/netsuite-sdk-py (github.com)

It’s already calling the sqlcache, I believe that’s what fails most times this runs

Any idea why it works flawlessly when I run within a workflow but not when the workflow is triggered via webhook? Might give a clue as to why the connection is timing out @U02SX7ETBFB

What path is it writing to?

No idea… all of that happens in the backend when I just call the SDK

Yeah but they offer a caching_path

You need to set it.

Pipedream only allows to write to /tmp

Another major difference between the workflow builder execution environment and a deployed one is the allocated memory.

For development speed, the workflow builder execution environment has more memory, so maybe try increasing memory, that might help with this intermittent issue.

I went with the cache_path solution, will monitor it for a while and try increasing memory limit if it fails…

Many thanks @U02SX7ETBFB

Nice to note about the memory difference… Pierce

Hi …

WF was previously on 120 seconds, and I Increased the memory to 512mb… It’s been throwing this on every run this morning. Normal time run ranges from 20-50000 milliseconds.

It runs when I test the workflow as usual.