"Map Service register Layers" python script error

4362
9
Jump to solution
03-10-2015 01:31 PM
ChristopherBoland
Occasional Contributor

I've been using this script successfully for months now to register large Map Services in ArcGIS Online to be included in OpenData, but recently (the last couple of weeks) I've been receiving this error:

     {'error':{'messageCode': 'CONT_0057', 'message': "Invalid JSON in 'text' parameter.", 'code': 400, 'details': []}}

I don't think anything has changed on my machine(s) and I'm not doing anything differently when creating my Map Service.  What am I doing wrong?  I've attached the whole python script.MapServiceLayerRegistrar.jpg

1 Solution

Accepted Solutions
ScottMoore__Olympia_
Esri Contributor

Hey there!  I just added a new script on GitHub that uses the latest version of ArcREST.  You can find it here:

here.

You need to download the latest version of ArcREST as well.  I made a note in the ReadMe.

View solution in original post

0 Kudos
9 Replies
MattCrossett
New Contributor III

Hi Chris,

   I'm experiencing the same as you. If I get an answer I'll post here.

Matt (our site is opendata.dc.gov)

0 Kudos
DanielFenton1
Regular Contributor

Chris,

Can you add a Try/ Except block around the res = agol.addItem... line of code?

In the except block it would be useful to Print serviceLayer.name.

That will help us debug what's being sent over to AGOL.

0 Kudos
ChristopherBoland
Occasional Contributor

Hi Daniel Fenton​,

Thanks for the suggestion.  As you said, I added the try statement before the indicated lines of code and added the

     except:

          print serviceLayer.name

statement after it and received the same results.  It runs through all of the items in the service, prints the feature class name and the feature class description, then throws this error:

{'error': {'messageCode': 'CONT_0057', 'message': "Invalid JSON in 'text' parameter.", 'code': 400, 'details': []}}

Would you rather work offline with this?  Also, FYI, I also put a note on GitHub and received an email from Scott Moore (the code developer) yesterday saying that he would try to look into it.

0 Kudos
DanielFenton1
Regular Contributor

Yes, but what is the name of the service?

0 Kudos
ChristopherBoland
Occasional Contributor

That's what I'm saying.  The script runs through all of the layers in the web mapping service, lists the name of the layers, lists the description of the layers, but doesn't create an AGOL item for any of them and throws the error.  It is not any one particular layer in the service and has occurred on many different web mapping services too, so not service specific. 

Currently I am trying it on this service:

http://ocean.floridamarine.org/arcgis/rest/services/Oil_Spill/ACPGRP/MapServer

Attached is the result of the script after running in IDLE:script failure.jpg

0 Kudos
ScottMoore__Olympia_
Esri Contributor

Hey there!  I just added a new script on GitHub that uses the latest version of ArcREST.  You can find it here:

here.

You need to download the latest version of ArcREST as well.  I made a note in the ReadMe.

View solution in original post

0 Kudos
ScottMoore__Olympia_
Esri Contributor

When I try to run the new version against your service, I get this stack trace.  Maybe there is some sort of network equipment that is blocking certain requests?

Traceback (most recent call last):

  File "C:\Users\scot5141\Documents\GitHub\OpenData-MapServiceLayerRegistrar\registerLayers2.py", line 20, in <module>

    for serviceLayer in fs.layers:

  File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\ags\mapservice.py", line 210, in layers

    self.__init()

  File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\ags\mapservice.py", line 77, in __init

    proxy_url=self._proxy_url)

  File "C:\Python27\ArcGIS10.3\lib\site-packages\arcrest\web\_base.py", line 153, in _do_get

    resp = opener.open(format_url)

  File "C:\Python27\ArcGIS10.3\lib\urllib2.py", line 404, in open

    response = self._open(req, data)

  File "C:\Python27\ArcGIS10.3\lib\urllib2.py", line 422, in _open

    '_open', req)

  File "C:\Python27\ArcGIS10.3\lib\urllib2.py", line 382, in _call_chain

    result = func(*args)

  File "C:\Python27\ArcGIS10.3\lib\urllib2.py", line 1214, in http_open

    return self.do_open(httplib.HTTPConnection, req)

  File "C:\Python27\ArcGIS10.3\lib\urllib2.py", line 1187, in do_open

    r = h.getresponse(buffering=True)

  File "C:\Python27\ArcGIS10.3\lib\httplib.py", line 1067, in getresponse

    response.begin()

  File "C:\Python27\ArcGIS10.3\lib\httplib.py", line 409, in begin

    version, status, reason = self._read_status()

  File "C:\Python27\ArcGIS10.3\lib\httplib.py", line 365, in _read_status

    line = self.fp.readline(_MAXLINE + 1)

  File "C:\Python27\ArcGIS10.3\lib\socket.py", line 476, in readline

    data = self._sock.recv(self._rbufsize)

error: [Errno 10054] An existing connection was forcibly closed by the remote host

0 Kudos
ChristopherBoland
Occasional Contributor

Thanks Scott!

I downloaded the new version of your script and installed ArcRest v2 and it ran perfectly on that rest endpoint.  I don't know why you were getting the stack trace, but it worked fine for me.

Thanks again,

Chris

AndrewTurner
Esri Contributor

Looking at the Add Item API documentation you’ll see that there is a “text” option for Items. That is likely what the error is responding to. However you are not explicitly trying to include a text parameter.

You could use Fiddler or other to capture the JSON being sent to AGOL – that would be the best way to see what you are sending. I’m curious if a “text” is getting added in the ArcREST (though looking at the source I don’t see that).

Alternatively you could add a text parameter that is a blank string. Maybe AGOL is now expecting the parameter (though it probably shouldn’t).

http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Add_Item/02r30000008q000000/

0 Kudos