# Http-functions from python

**URL:** <https://forum.wixstudio.com/t/http-functions-from-python/67421>\
**Category:** Ask the community\
**Tags:** code\
**Created:** [January 13, 2025, 5:06pm UTC](https://forum.wixstudio.com/t/http-functions-from-python/67421 "2025-01-13T17:06:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neuron\_Neuron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/neuron_neuron/32/103485_2.png) [@Neuron\_Neuron](https://forum.wixstudio.com/u/Neuron_Neuron)\
**Post date:** [January 13, 2025, 5:06pm UTC](https://forum.wixstudio.com/t/http-functions-from-python/67421/1 "2025-01-13T17:06:14Z")

</div>

Hi all, I’m using this test code in Python to access a simple database query in Wix:

```javascript
def check_user_id_in_wix(user_id):
    url = f"https://<my-site>/home/_functions/checkUserId"
    data = {"path": [
        "ASDFHFDFGHDHJDF"
    ],
        "headers": {
            "Accept": "*/*"
        },
        "query": {
            "myKey": "myValue"
        }}

    headers = {"Content-Type": "application/json"}

    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status()
        response_data = response.json()
        return response_data.get('found', False)

    except requests.exceptions.RequestException as e:
        print(f"Error querying Wix database: {e}")
        return False

```

This returns error 404. Using the same body in Wix test mode, I get a valid response. It’s my first time interfacing an external app with Wix so I’m lost.

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [January 14, 2025, 4:29pm UTC](https://forum.wixstudio.com/t/http-functions-from-python/67421/2 "2025-01-14T16:29:07Z")

</div>

I’m making an assumption here that this “checkUserId” is an http function that you have written on your Wix or Wix Studio site.

In that case, the url structure is incorrect. Take a look a the documentation here as it will depend on if you are accessing the call in a free or premium site as to what the structure must be.

For example, /home/ is not part of a valid path for an http func call.

[https://dev.wix.com/docs/velo/api-reference/wix-http-functions/introduction](https://dev.wix.com/docs/velo/api-reference/wix-http-functions/introduction)

---

<div class="post-metadata">

**Author:** ![Neuron\_Neuron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/neuron_neuron/32/103485_2.png) [@Neuron\_Neuron](https://forum.wixstudio.com/u/Neuron_Neuron)\
**Post date:** [January 16, 2025, 10:53am UTC](https://forum.wixstudio.com/t/http-functions-from-python/67421/3 "2025-01-16T10:53:46Z")

</div>

Hi and thanks for your reply. I changed the URL according to my understanding of how it should be formed, but I still get 404. Below is my Wix function (which works on the tester page in Wix):

```javascript
import { ok, notFound, serverError } from "wix-http-functions";
import wixData from "wix-data";

export function get_myFunction(request) {
  let options = {
    headers: {
      "Content-Type": "application/json",
    },
  };
  // Query a collection to find matching items.
  return (
    wixData
      .query("NSUsers")
      .eq("id", request.path[0])
      .find()
      .then((results) => {
        // Matching items are found.
        if (results.items.length > 0) {
          options.body = {
            items: results.items,
          };
          return ok(options);
        }
        // No matching items are found.
        options.body = {
          error: `'${request.path[0]}' was not found`,
        };
        return notFound(options);
      })
      // Something went wrong.
      .catch((error) => {
        options.body = {
          error: error,
        };
        return serverError(options);
      })
  );
}

```

And this is the Python code:

```javascript
def check_user_id_in_wix(user_id):
    data = {"path": [
        "ASDFHFDFGHDHJDF"
    ],
        "headers": {
            "Accept": "*/*"
        },
        "query": {
            "myKey": "myValue"
        }}
    headers = {"Content-Type": "application/json"}
    url = f"https://<my-site>.wixsite.com/mysite/_functions/myFunction/sub?q=" + json.dumps(data)

    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status() # Raise an exception for bad status codes
        print(response)

        response_data = response.json()
        return response_data.get('found', False)

    except requests.exceptions.RequestException as e:
        print(f"Error querying Wix database: {e}")
        return False

```

I have no idea of what I’m doing wrong.

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [January 16, 2025, 6:00pm UTC](https://forum.wixstudio.com/t/http-functions-from-python/67421/4 "2025-01-16T18:00:18Z")

</div>

You need to replace the default values in this url with your values

my-site → your actual site name  
myFunction → your actual function

and for the query param, i would test with a hardcoded vlaue first to confirm the url is working

> [@Neuron\_Neuron](#):
>
> `https://<my-site>.wixsite.com/mysite/_functions/myFunction/sub?q=" + json.dumps(data)`

one tip - an easy way to know if its working is to put the url in your browser. Running your pythin code is okay as well but this URL would be accessible by the browser once it’s correct
