Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

ArcRest was working then quit--no changes to script #345

Open
badavis57007 opened this issue Jun 7, 2017 · 18 comments
Open

ArcRest was working then quit--no changes to script #345

badavis57007 opened this issue Jun 7, 2017 · 18 comments

Comments

@badavis57007
Copy link

ArcRest

I wrote the following code. The code was running just fine. I installed ArcRest using PIP and it worked great. Then I was adding functionality, I ran it, Python hung up, then it crashed. If throws the following error below. See below for my fixes (I thought the file became corrupted). It was running fine and continues to fail. Nothing has changed in the code that I was using and it worked fine before. The security handler is not working anymore even though it is there. I have tried the security handler with arcrest.security.security.AGOLTokenSecurityHandler as well:

import arcrest
import os
import arcpy as env
import arcpy

arcpy.env.workspace = r"I:\GISStaff\Temp"

Step 3. Get Local Copy of AGOL Feature Services and put in File Geodatabase.

3A. Log into AGOL using AGOLTokenSecurity Handler and manageorg.administration to access content

uname = "Username"
pword = "Password"

site = "http://OrganizationAccount.maps.arcgis.com"

sh=arcrest.AGOLTokenSecurityHandler(uname, pword, site)
admin = arcrest.manageorg.administration.Administration(securityHandler=sh)
content = admin.content
user = content.users.user(uname)
print "accessed content"

Version or date of download

Downloaded June 7th. Using PIP. Version 3.5.9. When I reloaded this version with pip, it said it loaded successfully but there were failures listed in the command prompt before the successful note.

Bug

Repo Steps or Enhancement details

I thought it was corrupted. I uninstalled ArcMap, Python, everything. Did a full reinstall. It still throws the error listed below.
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.3\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in main.dict
File "\county.allegheny.local\users\DCS\T109840\Desktop\ExportAGOLLayer.py", line 19, in
sh=arcrest.AGOLTokenSecurityHandler(uname, pword, site)
File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\security\security.py", line 1177, in init
self._initURL(org_url=org_url,token_url=token_url)
File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\security\security.py", line 1205, in _initURL
proxy_url=self._proxy_url)
File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\web_base.py", line 598, in _get
ctx = ssl.create_default_context()
AttributeError: 'module' object has no attribute 'create_default_context'

@MikeMillerGIS
Copy link
Member

can you open a python command and try the following?

import ssl
ssl.create_default_context()

image

what happens?

What version of python are you using?

@badavis57007
Copy link
Author

import ssl
ssl.create_default_context()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'create_default_context'

I am running Python version 2.7.8. This is what came with the installation of ArcMap 10.3. I ran the same script multiple times before without changing it and it worked under all of the same programs and configurations. I uninstalled with pip and reinstalled and reinstalled arcrest after the complete uninstall/reinstall of arcmap.

@badavis57007
Copy link
Author

Sorry. 2.7.13

@MikeMillerGIS
Copy link
Member

the code should only run that section for python 2.7.9

what do you get when you run this
import sys
sys.version_info[0:3]

@badavis57007
Copy link
Author

2, 7, 13. I apologize I should have checked first

@MikeMillerGIS
Copy link
Member

I wonder if pip is upgrading your python, bet it is, you need to upgrade all requirements.

similar issue
epinna/weevely3#60

@MikeMillerGIS
Copy link
Member

@badavis57007
Copy link
Author

Ok. I successfully ran pip install tools. However, I cannot get any of the stackflow update recommendations to work. It keeps stating that the requirements.txt file does not exist. Did it put this in a different directory and do I have to change directories to run the upgrade requirements tool?

image

@MikeMillerGIS
Copy link
Member

I am unsure, not a PIP expert.

maybe this will help
http://www.idiotinside.com/2015/05/10/python-auto-generate-requirements-txt/

@MikeMillerGIS
Copy link
Member

Here is my ssl.py in case you just want to manually place it in you lib folder
ssl - Copy.py.txt

@badavis57007
Copy link
Author

So. I tried everything you suggested. I cannot get the requirements.txt to generate at all. I have tried the tools on GitHub (geoprocessing tool).

image

I also tried to uninstall and reinstall arcrest and here is the message I get in the command window. The first time I loaded this, it came in fine. I was using 2.7.8 but just realized visual studio upgraded me to the above listed version. Note. I uninstalled visual studio before the uninstall/reinstall of arcgis and all of its components. I cannot figure out why this thing keeps failing on a previously working code and why I cannot upgrade arcrest. If I cannot figure this out, I may have to switch to trying ESRI's Python API that is in Beta.

image

@MikeMillerGIS
Copy link
Member

you have mixed version of python and its components. Why not try install py 2.7.13 on top over your current install, that might fix it.

https://www.python.org/downloads/release/python-2713/

ArcRest is only checking version for that function. You could change the source to check for that function in ssl instead of version or you could just change that check.

In the _web.py file, find all sys.version_info[0:3] and the following line checks the version, change that to a version above yours

@badavis57007
Copy link
Author

badavis57007 commented Jun 8, 2017

I upgraded to 2.7.13 over top of the ArcGIS installed Python.

I found the _web.py file. These are the only lines that come remotely close to the "sys.version_info[0:3]" you discussed above. In case you haven't guessed, I am rather novice at this so I'm doing my best to try to follow along. I haven't changed anything because the other parts of the version [1:3] are missing and I am unsure what to change here.

image

Also, when you say "ArcRest is only checking version for that function. You could change the source to check for that function in ssl instead of version or you could just change that check." How exactly do I do this? I was unable to figure this out on my own.

@badavis57007
Copy link
Author

I got it. I went into the >Site-packages\ArcRest\web\base.py and changed the version to 3.1.1 in the sys.version_info[0:3] >= (3, 1, 1). It runs again. Thank you for your assistance in this.

@badavis57007
Copy link
Author

The traceback errors indicated the file to correct.

Traceback (most recent call last):
File "C:\Python27\ArcGIS10.3\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in main.dict
File "\county.allegheny.local\users\DCS\T109840\Desktop\ExportAGOLLayer.py", line 19, in
sh=arcrest.AGOLTokenSecurityHandler(uname, pword, site)
File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\security\security.py", line 1177, in init
self._initURL(org_url=org_url,token_url=token_url)
File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\security\security.py", line 1205, in _initURL
proxy_url=self._proxy_url)
File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\web_base.py", line 598, in _get
ctx = ssl.create_default_context()
AttributeError: 'module' object has no attribute 'create_default_context'

@MikeMillerGIS
Copy link
Member

So you are all set?

@badavis57007
Copy link
Author

Yes. I'm back to scripting. Thank you again for your help. I am more of Python Scripter than a programmer. I learned a lot about how Python is structured and coded. I still have a lot to learn this helped a lot. If you can suggest any additional references to learn more about Python, I would be eager to learn more.

MikeMillerGIS added a commit that referenced this issue Jun 8, 2017
@MikeMillerGIS
Copy link
Member

I checked in a fix that will help with this issue in the future. This not only checks the version, but checks to ensure the function exist

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants