My organization just been equiped with ArcMap and ArcGIS Server and I already encountered problem when trying to publish python script as geoprocessing services when some python modules are imported
Those problematic python modules I have encoutered so far are urllib2 and uuid
If you do
import urllib2 or import uuid , your script cannot published on the server, the publishing tool go idle and you have to kill the process.
But, if you do from urllib2 import * or from uuid import * , your script can be published.
This workaround can be problematic if classes or method in two modules have the same name.
Is this a problem ESRI is aware of? Why those particular modules are causing this error?
There were changes to urllib2 which may account for the behaviour
20.6. urllib2 — extensible library for opening URLs — Python 2.7.12 documentation
from 2to3
urllib
https://docs.python.org/3.4/library/2to3.html?highlight=urllib2#2to3fixer-urllib
Handles the rename of urllib
and urllib2
to the urllib
package.
21.5. urllib — URL handling modules — Python 3.4.5 documentation
perhaps it is future-proofing like the examples here that work in python 2 and 3
Quick-start guide — Python-Future documentation
and there is even a pypi package that was used for those that need this
future 0.15.2 : Python Package Index
It seems like a wise compromise to ensure 2 and 3 functionality
I am not sure to understand your answer. I am using python 2.7 only, on server and on desktop, not python3.
read the docs, they have future proofed the 2.7 version, the way you don't want to import urllib2 is now the accepted method since its previous incarnate has been split up. It is not an onerous change and you will be ready when you need to migrate to 3.x.
Oh, it is also possible that just because you are running 2.7 it doesn't mean that something else up the software ladder may be running a higher version, but I don't know your network setup. It is better to error on the side of caution
Ok I get it. It's true that it's not an onerous change.
I wonder if the reason why arcgis is modifiying the script and the way modules are imported during the publish process is to ensure that if the script was made with python3 (arcgis pro), it will be compatible with python2.7 installed on arcgis server?
I have opened a python console on the server and doing import urllib2 is working.
Just a side note on importing custom modules (which is not the case for you):
Authoring geoprocessing tasks with Python scripts—Documentation | ArcGIS for Server
However, may be interesting when in the future you are going to use imports of you own modules in scripts published to the server.
After a long idle time (several hours), the Publisher returns the following errors:
High Unresolved 00178 Data: C:\Windows\bfsvc.exe, used by Script Script cannot be copied to the server