I have created a simple script tool that should get one parameter (a feature class) and print some unique values from a single field. The Python code looks like this:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">get_species</SPAN><SPAN class="punctuation token">(</SPAN>observationFeatureClass<SPAN class="punctuation token">,</SPAN> field<SPAN class="punctuation token">,</SPAN> query<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>observationFeatureClass<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN>field<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> query<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> species<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">return</SPAN> sorted<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>s<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> s <SPAN class="keyword token">in</SPAN> species<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
ofc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
fld <SPAN class="operator token">=</SPAN> <SPAN class="string token">"gatunek"</SPAN>
qry <SPAN class="operator token">=</SPAN> <SPAN class="string token">"kategoria = 'inwazyjna'"</SPAN>
<SPAN class="keyword token">for</SPAN> i<SPAN class="punctuation token">,</SPAN> s <SPAN class="keyword token">in</SPAN> enumerate<SPAN class="punctuation token">(</SPAN>get_species<SPAN class="punctuation token">(</SPAN>ofc<SPAN class="punctuation token">,</SPAN> fld<SPAN class="punctuation token">,</SPAN> qry<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> start<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>f<SPAN class="string token">"Gatunek nr {i}: {s}"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If I run this tool straight from the ArcGIS Pro, providing a hosted feature service as a parameter, everything works well. But, when I publish the result as a Web Tool on our portal, it is unable to access the service and it returns: "RuntimeError: cannot open <Hosted Feature Service URL here>".
Previously, we had a problem with accessing protected resources from a custom print service and it was resolved by applying a patch, but this tool fails regardless of the service permissions.
We work with ArcGIS Pro 2.5 and ArcGIS Enterprise 10.7.