Generic error "Statement error: User code error" when running Notebook from Data Pipeline

Data Factory

I am brand new to Fabric and somewhere around a beginner level of Python understanding. My client setup this instance of Fabric and I believe they are still on a trial capacity.

I am trying to source data from a custom API, of which I cannot modify. Using Postman and PyCharm, I can run this query, no issues. The API sends data back in chunks of up to 10,000 rows at a time. I have no idea if I'll get 1 page of data or 100.

It took almost 30 seconds to ~2 minutes to run in Postman. It took less than a minute in PyCharm.

I run into issues when I copy the code into a Fabric Python Notebook (no need for Spark here).

If I call the Notebook from a Data Pipeline, I receive a generic error message, "Statement error: User code error". It seems to error relatively quickly, anywhere from about 40 seconds up to a couple minutes. The 'finally' block is never reached.

If I run the Notebook from directly inside the Notebook, it runs for 1-2 minutes. It never throws an error/exception, but it also never gets past the 'requests.get(...)' line either. The 'finally' block is never reached.

Any thoughts? Is there a way to get more detailed logging or something? I feel like this is a Fabric specific issue since I can make the Postman and PyCharm calls without issue.

import sys
import requests

param_endpoint = "sales"

if not param_endpoint:
    print("No endpoint parameter given, cannot continue.")
    sys.exit(1)

print("endpoint:" + param_endpoint)

def make_api_request(base_url, final_path, api_key, device_id, query_params=None):
    headers = {
        'KEY': api_key,
    }
    full_url = f"{base_url}{final_path}"

    try:
        print('full_url: ' + full_url)
        print('api_key: ' + api_key)

        # Using requests with custom timeouts
        response = requests.get(full_url,
                                headers=headers,
                                params=query_params,
                                timeout=(60.0, 600.0))
        print("post-response") # NEVER makes it to here inside Fabric

        print(type(response))
        print(response)

        response.raise_for_status()
        return response.json()
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        print("finally block")


base_url = "..."
api_key = "..."

api_response = make_api_request(base_url, "sales", api_key)

print("API response:", api_response)

https://preview.redd.it/0llov619dvte1.png?width=847&format=png&auto=webp&s=5fe87e28498781db706e5563b57589432b68076e

Posted Apr 9, 2025, 8:32 PM UTC

10
Loading comments…