Connection Error - GIS() class

1205
8
Jump to solution
06-01-2022 04:51 PM
neil_perol
New Contributor II

Hi all. I'm very new to ArcGIS Pro and the ArcGIS API for Python. It says in the documentation that if I install ArcGIS Pro, I don't need any other installations, however, I've been having this connection issue at the very first step:

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
gis = GIS()

neil_perol_1-1654127122107.png

Anyone knows what's happening here and if I need additional installations/environments?

Installed: ArcGIS Pro 2.8, Python 3.7.10, ArcGIS API 1.8.5

 

0 Kudos
1 Solution

Accepted Solutions
neil_perol
New Contributor II

I found the underlying issue with this, and it's because of the network firewall. I am working on a government building and we have a very secure network which closes the connection as soon as it's made. I tried the codes at home and they work just fine.

View solution in original post

8 Replies
Brian_Wilson
Occasional Contributor III

arcgis module is for talking to ArcGIS Online or ArcGIS Enterprise

I always feed it the URL of my server, like this for example

gis = GIS(url="https://myserver/portal", user="rocky", password="flyingsquirrel")

In theory there are defaults, but they don't work for me. You probably have to be running from inside ArcGIS Pro or something and I never am. I work in Visual Studio Code all the time.

 

BTW you don't even need ArcGIS Pro installed, you can install the arcgis module directly into a separate Conda environment on a machine that does not have ArcGIS Pro installed and it will still work. I use it on Linux.

 

neil_perol
New Contributor II

Hi Brian, thanks for the reply.

Theoretically, I should still be have an anonymous connection to www.arcgis.com if I use gis = GIS().
I also tried adding portal url before posting this question, but I still couldn't connect. A different error though:

neil_perol_0-1654129610774.png

 

 

0 Kudos
Brian_Wilson
Occasional Contributor III

I was able to connect using just "gis = GIS()" and I was able to walk through the Esri code in a debugger.

if you leave out the URL it plugs in "https://www.arcgis.com".

If you leave out password but give it a user it will prompt you to type a password.

If you leave out username then it tries to use a token from your environment settings.

If you don't have a token in your environment and no username or password it create an anonymous login.

If there is a token setting and the token is wrong that would do it. The setting is "ESRI_API_KEY".

The other advice I could offer is, get a good Python debugger if you are not already using one. I recommend Microsoft Visual Studio Code, it's free, I spend about 6 1/2 hours of my workday using it. There is a setting you need to put in launch.json file "justMyCode = false" to get it to go into the Esri code. If you did this you could see a little more of what is happening. I can walk you through that if you go that route.

0 Kudos
Brian_Wilson
Occasional Contributor III

It's too bad so few Esri error messages are actually connected to the underlying problem.

Often they only make sense after you solve the problem.

 

0 Kudos
neil_perol
New Contributor II

Thanks for your replies, Brian. They were very informative. However, I found out that the issue is with the network firewall which is very strict. I tried the codes at home and they work just fine. 🙂

0 Kudos
neil_perol
New Contributor II

A different error when a portal url is added:

neil_perol_0-1654129019831.png

 

0 Kudos
neil_perol
New Contributor II

I found the underlying issue with this, and it's because of the network firewall. I am working on a government building and we have a very secure network which closes the connection as soon as it's made. I tried the codes at home and they work just fine.

RachelGomez
New Contributor II

Tips to fix-

Restart your computer.
Make sure your wireless adapter is enabled.
Restart your modem and router.
Try a hard network reset.
Move closer to the router.
Try using Ethernet.

 

Regards,

Rachel Gomez

0 Kudos