Hi all,
Trying to automate the updating of a large tpk on AGOL. When the tpk is updated on my servers I do the following:
- Break into parts
- Call updateItem opeartion with multipart = true
- make a request to upload each part using addPart
- make a request with the commit function to finalize the update to the tpk on AGOL
My issue is that I get no response when trying to use addPart, then when the commit is finally hit in my code it says there are no parts to commit:
Code:
update_url <SPAN class="operator token">=</SPAN> <SPAN class="string token">'https://lipa.maps.arcgis.com/sharing/rest/content/users/{}/items/{}/update'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>tpk_id<SPAN class="punctuation token">)</SPAN>
up_data <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">'json'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">:</SPAN>token<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'title'</SPAN><SPAN class="punctuation token">:</SPAN> layer_name<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'itemId'</SPAN><SPAN class="punctuation token">:</SPAN>tpk_id<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'type'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Tile Package'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'overwrite'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'true'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="comment token"># existing item, overwrite is set to true</SPAN>
<SPAN class="string token">'async'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">'true'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'multipart'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"true"</SPAN><SPAN class="punctuation token">}</SPAN>
update_response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>post<SPAN class="punctuation token">(</SPAN>update_url<SPAN class="punctuation token">,</SPAN> up_data<SPAN class="operator token">=</SPAN>data<SPAN class="punctuation token">,</SPAN> verify <SPAN class="operator token">=</SPAN> cert<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>json<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> update_response
part_num <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
part_url <SPAN class="operator token">=</SPAN> <SPAN class="string token">'https://lipa.maps.arcgis.com/sharing/rest/content/users/{}/items/{}/addPart'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>tpk_id<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> part <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>parts<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"\\psegliny.com\oms\oms_gis_prd\fileshare_mapping\cache_extent\es_secondary_tpks\full_service_area"</SPAN>
part <SPAN class="operator token">=</SPAN> path <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>part<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> part
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>part_num<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">##files_up = {"file": open(part, 'rb')}</SPAN>
<SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>part<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"rb"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> f<SPAN class="punctuation token">:</SPAN>
files_up <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"file"</SPAN><SPAN class="punctuation token">:</SPAN>f<SPAN class="punctuation token">}</SPAN>
data <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">'json'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">:</SPAN>token<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'partNum'</SPAN><SPAN class="punctuation token">:</SPAN>part_num<SPAN class="punctuation token">}</SPAN>
part_response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>post<SPAN class="punctuation token">(</SPAN>part_url<SPAN class="punctuation token">,</SPAN>data <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">,</SPAN>files<SPAN class="operator token">=</SPAN>files_up<SPAN class="punctuation token">,</SPAN>verify<SPAN class="operator token">=</SPAN>cert<SPAN class="punctuation token">)</SPAN>
part_num<SPAN class="operator token">+=</SPAN><SPAN class="number token">1</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
jres <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>part_response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> jres
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"no response"</SPAN>
<SPAN class="comment token">##print add_part_response</SPAN>
commit_url <SPAN class="operator token">=</SPAN> <SPAN class="string token">'https://lipa.maps.arcgis.com/sharing/rest/content/users/{}/items/{}/commit'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>tpk_id<SPAN class="punctuation token">)</SPAN>
data <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">'json'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">:</SPAN>token<SPAN class="punctuation token">}</SPAN>
commit_response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>post<SPAN class="punctuation token">(</SPAN>commit_url<SPAN class="punctuation token">,</SPAN>data<SPAN class="operator token">=</SPAN>data<SPAN class="punctuation token">,</SPAN>verify<SPAN class="operator token">=</SPAN>cert<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>json<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> commit_response
<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></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><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></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><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Anyone know what the issue is?