# TypeError on avoid polygons function

**URL:** https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062
**Category:** QGIS
**Created:** [August 12, 2021, 12:04am UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062 "2021-08-12T00:04:48Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 12, 2021, 12:04am UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/1 "2021-08-12T00:04:48Z")

</div>

Hi,  
I’m trying to use the avoid polygon function, but a TypeError keeps coming up. I’ve tried using different formats and the same error message about exceptions show. The first exception says Network error:network access disabled and the second says typeerror. I’m not an expert in python so apologies if its an easy fix

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 12, 2021, 7:22am UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/2 "2021-08-12T07:22:23Z")

</div>

Hi @nj7,

without the actual polygon and lines for the request it will be rather difficult to help.

Best regards

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 13, 2021, 12:20pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/3 "2021-08-13T12:20:23Z")

</div>

Hi @amandus, thanks for your reply  
I’m not sure if I can share the files as this is for a university project and there are a lot of rules on data protection, but I’ll check with my supervisor. If it helps identify a common problem, I have a road system and a polygon of a flooded area that needed to be clipped to reduce the number of features.  
I have managed to figure out that the issue is on line 161 of the python plugin client file, but I can’t open this file to see what this line does.  
Hope this clears things up,sorry if its not enough information to identify the issue, hopefully at the very least its enough to know what to look for.  
Thanks for your help

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 13, 2021, 12:28pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/4 "2021-08-13T12:28:10Z")

</div>

Maybe you could try to reproduce the problem with a different polygon and share that one?  
You can also try to validate you polygon with a geojson validator e.g. [geojson.io](http://geojson.io).

Also the code for the plugin is [open source](https://github.com/GIScience/openrouteservice-py/blob/master/openrouteservice/client.py). Maybe you can point to the correct line in this file, because 161 in client.py is a comment 😅

Best regards

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 16, 2021, 3:09pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/5 "2021-08-16T15:09:57Z")

</div>

Hi, I’ve recreated the issue with another polygon, how can I upload it on here as a geojson file?  
The error message I get says the issue is when line 161 is called, so not sure what it means then.  
Thanks

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 16, 2021, 7:35pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/6 "2021-08-16T19:35:19Z")

</div>

just paste the content in a code block by using these quotes:

````auto
```
{
  "type": "Polygon",
  "geometry": [...
```

````

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 16, 2021, 7:46pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/7 "2021-08-16T19:46:23Z")

</div>

oooh, whait a moment…  
you are talking about the QGIS plugin.  
You even put it in the correct category…  
You referred to it as the _python plugin_ which in my head is the [openrouteservice-py package](https://github.com/GIScience/openrouteservice-py)

The line 161 makes a lot more sense now.

Could you please paste the whole error log message (in case of sensitive info please redact it)

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 16, 2021, 8:55pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/8 "2021-08-16T20:55:35Z")

</div>

ah my bad, should have been clearer. Heres the error message 🙂  
Traceback (most recent call last):  
File “C:/Users/njone/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\common\client.py”, line 161, in request  
blocking=True)  
File “C:/Users/njone/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\common\networkaccessmanager.py”, line 260, in request  
raise self.http\_call\_result.exception  
ORStools.common.networkaccessmanager.RequestsException: Network error: Network access is disabled.

```
         During handling of the above exception, another exception occurred:
         
         Traceback (most recent call last):
          File "C:/Users/njone/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\gui\ORStoolsDialog.py", line 309, in run_gui_control
          response = clnt.request('/v2/directions/' + profile + '/geojson', {}, post_json=params)
          File "C:/Users/njone/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\common\client.py", line 167, in request
          self._check_status()
          File "C:/Users/njone/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\common\client.py", line 219, in _check_status
          if 400 TypeError: '
```

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 16, 2021, 9:05pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/9 "2021-08-16T21:05:09Z")

</div>

heres the trial polygon i made as well

```auto
{
  "type": "Polygon",
  "geometry": [3.1743869612910203e-06, 0.008458165209773319 : 3.013473303781211e-06, 0.008180230790309318 : 3.013473303781211e-06, 0.008180230790309318 : 3.013473303781211e-06, 0.008180230790309318 : 
3.386500338820042e-06, 0.00910338474899331 : 3.013473303781211e-06, 0.008180230790309318 : 3.386500338820042e-06, 0.00910338474899331 : 3.386500338820042e-06, 0.00910338474899331: 3.1743869612910203e-06, 0.008458165209773319 : 3.386500338820042e-06, 0.00910338474899331 : 3.1743869612910203e-06, 0.008458165209773319 : 3.1743869612910203e-06, 0.008458165209773319

```

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 17, 2021, 11:56am UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/10 "2021-08-17T11:56:08Z")

</div>

Hi @nj7,

this is not a valid GeoJSON polygon.  
It should look something like this:

```auto
{
        "type": "Polygon",
        "coordinates": [
          [
            [
              4.19677734375,
              1.404735957542484
            ],
            [
              4.141845703125,
              1.4761245198527841
            ],
            [
              3.99078369140625,
              1.3731595449619909
            ],
            [
              4.0045166015625,
              1.1905576261723045
            ],
            [
              4.23248291015625,
              1.3113784096477825
            ],
            [
              4.19677734375,
              1.404735957542484
            ]
          ]
        ]
      }

```

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 17, 2021, 12:05pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/11 "2021-08-17T12:05:23Z")

</div>

> [@nj7](#):
>
> ```auto
> File "C:/Users/njone/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\common\client.py", line 219, in _check_status
> if 400 TypeError: '
> 
> ```

Is that the last of the error message?  
The request seems to be malformed and returns a http 400 response.  
probably due to the polygon that is passed.  
But normally the error message should be more verbose.

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 17, 2021, 12:08pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/12 "2021-08-17T12:08:12Z")

</div>

Apologies I’ll reformat it now

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 17, 2021, 12:12pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/13 "2021-08-17T12:12:02Z")

</div>

Yes thats the end of the message. If its reoccuring with other polygons, could it be an issue with my QGIS? I have version 3.16.5 on my laptop.

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 17, 2021, 12:16pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/14 "2021-08-17T12:16:09Z")

</div>

hmm should not be the qgis version. i’m using 3.16.6 but that shouldn’t make a difference.

Are you passing the polygons as scratch layers?  
Or how is the your workflow to create avoid polygons and start/end points?

---

<div class="post-metadata">

### Author: ![nj7](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nj7/32/1211_2.png) [@nj7](https://ask.openrouteservice.org/u/nj7)
#### Post date: [August 17, 2021, 12:50pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/15 "2021-08-17T12:50:32Z")

</div>

The polygons were properly saved and I was working with the advanced directions dialogue box in the ORS tools.  
Good news though, it has started working! I hadn’t changed anything from my previous attempt, so still no idea what the issue is though.  
As with any computing project, its from one problem to another… I’ve cut the actual polygon down to a size the program can manage, but now it says the network request has timed out. Is there any way around this?  
Thanks for your help

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [August 17, 2021, 1:06pm UTC](https://ask.openrouteservice.org/t/typeerror-on-avoid-polygons-function/3062/16 "2021-08-17T13:06:43Z")

</div>

sorry, but i’m lost here.

normally there should be a meaningful error message in the log text window of the advanced directions tab. As well as the ORS Tools and Python error Log tabs like:

```auto
ApiError: 400 ({"error":{"code":2003,"message":"The area of a polygon to avoid must not exceed 2.0E8 square meters."},"info":{"engine":{"version":"6.6.1","build_date":"2021-07-05T10:57:48Z"},"timestamp":1629204996772}})

```

which appears if your avoid polygons exceed the maximum size of 200 km^2.

Maybe that is the problem with the request.

However, if i can’t reproduce the actual request, it’s rather hard to get to the source the problem
