ToolJet/docs/versioned_docs/version-2.68.0/contributing-guide/troubleshooting/runpy-limits.md
Aman Regu bdfe3270e2
[docs]: v2.68.0-Beta (#10755)
* docs: jira

* docs: formatting + Client Credentials grant type

* docs: connection string pgsql

* docs: parameterized queries mysql

* docs: parameterized queries in PostgreSQL

* docs: update mysql example

* docs: TJDB sql editor

* docs: add metadata to REST API

* docs: add, update  postgresql media

* docs: add metadata to graphql

* docs: update parameterized queries

* docs: add parameterized queries for mssql

* docs: add SSL Cert to mysql

* docs: TJDB SQL restricted commands

* docs: update JIRA token location

* docs: update delete issue example

* docs: update find user by query example

* docs: remove session id from get assignable users

* docs: use correct image for get issues for board

* docs: update create issue example

* docs: update delete issue media

* docs: update assignable users media

* docs: update examples

* docs: update key desc

* docs: v2.68.0-Beta
2024-09-13 19:23:19 +05:30

1.8 KiB

id title
runpy-limitations RunPy limitations

Limitation: Unable to Open External URLs with urlopen in RunPy

When using the urlopen function within a RunPy query, you may encounter an error when trying to open external URLs, such as https://api.baserow.io. This limitation is due to the underlying framework used by RunPy, Pyodide, which has certain constraints and may not support all features available in a standard Python environment.

Solution: Using fetch function with JavaScript

To overcome this limitation, you can utilize the fetch function from JavaScript, as Pyodide supports interoperability between Python and JavaScript. Here's an example of how to make an HTTP request using the fetch function in a RunPy query:

from js import fetch
import json

async def push_data(url, data):
    response = await fetch(
        url,
        method='POST',
        headers=[
            ["Authorization", "Token <my_token>"],
            ["Content-Type", "application/json"]
        ],
        body=data
    )
    reply = await response.json()
    return reply

url = "https://api.baserow.io/api/database/rows/table/.../?user_field_names=true"
reply = await push_data(url, json.dumps(<my_data>))
reply

In the example above, the fetch function is used to make an HTTP POST request to the specified URL. The Authorization header is included to provide the necessary authentication token, and the request body is passed as JSON data.

By using the fetch function and incorporating JavaScript interoperability, you can successfully make HTTP requests within a RunPy query in scenarios where urlopen may encounter limitations.

It's important to note that the solution provided here assumes you have the necessary authorization token and data to push to the Baserow table. Adjust the code accordingly to fit your specific requirements.