Using arcpy to copy a portal feature service to a fgdb feature class

13932
17
Jump to solution
01-10-2020 10:07 AM
JoeBorgione
MVP Emeritus

ArcGIS Pro 2.4.3

In pro, you can add a feature service and manually export the features to a file geodatabase feature class.

How do you mimic that functionality in python?  I have tried:  

import arcpy
source = r'https://path/toOur/rest/services/MapServer/0'

arcpy.FeatureClassToFeatureClass_conversion(source,r'C:\pathTo\Test.gdb','newFC')

and get :

ExecuteError: ERROR 000210: Cannot create output C:\pathTo\Test.gdb\newFC
Failed to execute (FeatureClassToFeatureClass).

I googled the error, and then tried to use the same python approach with an Egdb feature class as the source, and it worked splendidly.  Is this a case for the python api?

That should just about do it....
0 Kudos
17 Replies
KatGIS
by
Occasional Contributor

Thanks, this is helpful! What would be the most efficient way to include attachments with the feature layer? 

0 Kudos
JamesTurner2
Regular Contributor

Is there an modification of this that would work with an enterprise geodatabase? I have a script uses the API to query a feature service and then export the data to a table (no spatial data) in my EGDB. I also use arcpy to set privileges'. I currently use the API and ArcPy, I'm wondering if there is a way to do something similar to the .save() method to eliminate the arcpy. I suppose I could do something like an append to get around overwriting the entire table and having to reset privileges.

0 Kudos
JoeBorgione
MVP Emeritus

Joshua- following the instructions given here: Working with different authentication schemes | ArcGIS for Developers  I'm taking a slightly different approach in passing the user, and pwd variables; I need to pass a 'client_id' as well:

gis = GIS(url_gis,user,pwd,client_id = 'Ox05rrnllB1biFgW')

But I get an error:

  File "C:\EnvClones\arcgispro-py3-clone243\lib\site-packages\arcgis\_impl\connection.py", line 449, in oauth_authenticate
    from bs4 import BeautifulSoup

ModuleNotFoundError: No module named 'bs4'‍‍‍‍

Not having a whole lot of luck with dr.google trying to find a remedy for this: it seems as though with the python 3.6 install from Pro, bs4 is no where to be found...

edited to add: actually found a couple threads that suggest using pip3 to install bs4 into python 3.6: here is one from quoraAnaconda offers one as well.  I guess I need to use one of these while in my cloned environment?

That should just about do it....
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It appears to be trying to load a Python package/module that isn't installed in your virtual env.  Confirm that beautifulsoup4 is installed, and if not, install it.  It might be a defect in ArcGIS API for Python where they aren't packaging a dependency. 

0 Kudos
JoeBorgione
MVP Emeritus

From Esri Tech Support:  BUG-000118107 - In ArcGIS API for Python, requests for installing a third-party module named bs4 when the User Authentication with OAuth 2.0 method is used to login into ArcGIS Online.

by the way:

Kory Kramer

That should just about do it....
0 Kudos
KoryKramer
Esri Community Moderator
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I must be clairvoyant.  Nah, just worked with Esri for a long time.   This bug is fairly simple to work around yourself, assuming there isn't yet another bug just waiting right around the corner once the package import is resolved. 

0 Kudos
JoeBorgione
MVP Emeritus

After going back and forth on this with the portal admin here, Joshua's approach works for me.

That should just about do it....
0 Kudos