<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to call a Web Service from Python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175783#M13515</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a sample source code in Python that shows&amp;nbsp;how to call a web service from Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to make a call to a web service with a structure similar to this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;https://wwww.example.com/GISAddress/Check.asmx/VerifyAddress?param1=100 SW 10 street&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any samples showing the URL part and the variables part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Aug 2019 18:04:10 GMT</pubDate>
    <dc:creator>JoseSanchez</dc:creator>
    <dc:date>2019-08-30T18:04:10Z</dc:date>
    <item>
      <title>How to call a Web Service from Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175783#M13515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a sample source code in Python that shows&amp;nbsp;how to call a web service from Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to make a call to a web service with a structure similar to this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;https://wwww.example.com/GISAddress/Check.asmx/VerifyAddress?param1=100 SW 10 street&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any samples showing the URL part and the variables part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Aug 2019 18:04:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175783#M13515</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2019-08-30T18:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a Web Service from Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175784#M13516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/6555" target="_blank"&gt;Jose&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The easiest way to&amp;nbsp;GET&amp;nbsp;or POST a response from a web service from Python is using &lt;A href="https://pypi.org/project/requests/" rel="nofollow noopener noreferrer" target="_blank"&gt;requests&lt;/A&gt;.&amp;nbsp; You do not note what version of python you are using so you may need to install requests using the command &lt;STRONG&gt;pip install requests&lt;/STRONG&gt;.&amp;nbsp; You also do not indicate if your web service requires authentication.&amp;nbsp; The examples below do not&amp;nbsp;use authentication but this can be included.&amp;nbsp; Depending upon the encoding your web service uses, there may be issues with how the &amp;lt;white spaces&amp;gt; are handled in your address string.&amp;nbsp; Some use "+" while others use "%20" or "%".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; requests

url &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'https://wwww.example.com/GISAddress/Check.asmx/VerifyAddress'&lt;/SPAN&gt;
payload &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'param1'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'100 SW 10 street'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# add paramaters to the dictionary as needed&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# GET Only&lt;/SPAN&gt;
r &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; requests&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;url&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# GET with parameters&lt;/SPAN&gt;
r &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; requests&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;url&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; params&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;payload&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# POST with parameters&lt;/SPAN&gt;
r &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; requests&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;post&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;url&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; data&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;payload&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# URL, Response and Status&lt;/SPAN&gt;
r&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;url
r&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;text
r&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;status_code‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:04:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175784#M13516</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2021-12-11T09:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a Web Service from Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175785#M13517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am currently using Python 2.7.10 and the web service does not require authentication.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am able to call the web service in Python using the script below and I get a return in XML format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Questions: how do I parse the answer to get only the part I need a "Y' or&amp;nbsp; a "N"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what&amp;nbsp; I get on line:&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;t = ET.fromstring(the_page)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;string xmlns="http://www.example.comv/GISAddress"&amp;gt;Y&amp;lt;/string&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Source code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;import arcpy, urllib, urllib2,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;url = r'https://wwww.example.com/GISAddress/Check.asmx/VerifyAddress'&lt;BR /&gt; values = {'myAddress' : '100 SW 10 street'}&lt;/P&gt;&lt;P&gt;data = urllib.urlencode(values)&lt;BR /&gt; req = urllib2.Request(url, data)&lt;BR /&gt; response = urllib2.urlopen(req)&lt;BR /&gt; the_page = response.read()&lt;BR /&gt; t = ET.fromstring(the_page)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2019 15:39:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175785#M13517</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2019-09-03T15:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a Web Service from Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175786#M13518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/6555"&gt;Jose,&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add one more line - &lt;STRONG&gt;t.text&lt;/STRONG&gt; this should return just the 'Y' valve for your code example.&amp;nbsp; I assume you also have&amp;nbsp;&lt;STRONG&gt;xml.etree.ElementTree as ET&lt;/STRONG&gt; in your import statement and that there will only ever be a single line response from the web service.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2019 16:03:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175786#M13518</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2019-09-03T16:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a Web Service from Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175787#M13519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Lance, &lt;STRONG&gt;t.text&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp; works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please recommend&amp;nbsp;any good documentation that explains how to call web services using&amp;nbsp;&amp;nbsp; requests or&amp;nbsp; urllib, urllib2, and how to parse the results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2019 16:51:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175787#M13519</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2019-09-03T16:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a Web Service from Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175788#M13520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/6555"&gt;Jose&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at the following references:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="link-titled" href="https://docs.python.org/2/library/xml.etree.elementtree.html" title="https://docs.python.org/2/library/xml.etree.elementtree.html"&gt;19.7. xml.etree.ElementTree — The ElementTree XML API — Python 2.7.16 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="link-titled" href="https://docs.python.org/2/library/urllib.html" title="https://docs.python.org/2/library/urllib.html"&gt;20.5. urllib — Open arbitrary resources by URL — Python 2.7.16 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="link-titled" href="https://docs.python.org/2/library/urllib2.html" title="https://docs.python.org/2/library/urllib2.html"&gt;20.6. urllib2 — extensible library for opening URLs — Python 2.7.16 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would also recommend taking a look at using the Requests module noted in my original post.&amp;nbsp; It greatly simplifies HTML requests which can be cumbersome using urllib and urllib2. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A href="https://pypi.org/project/requests/2.7.0/" style="background-color: transparent; color: #2989c5; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;" title="https://pypi.org/project/requests/2.7.0/"&gt;requests · PyPI&lt;/A&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; word-wrap: break-word;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="link-titled" href="https://2.python-requests.org/en/master/" title="https://2.python-requests.org/en/master/"&gt;https://2.python-requests.org/en/master/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="link-titled" href="https://2.python-requests.org/en/master/user/quickstart/#make-a-request" title="https://2.python-requests.org/en/master/user/quickstart/#make-a-request"&gt;https://2.python-requests.org/en/master/user/quickstart/#make-a-request&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="link-titled" href="https://realpython.com/python-requests/" title="https://realpython.com/python-requests/"&gt;https://realpython.com/python-requests/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also recommend that you Google "GET and POST requests using Python", there is a lot of information out there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are going to be using Python on a regular basis I highly recommend &lt;A href="https://www.amazon.com/Python-Essential-Reference-David-Beazley/dp/0672329786"&gt;David Breazley's - &lt;EM&gt;Python Essential Reference&lt;/EM&gt;&lt;/A&gt;.&amp;nbsp; I have the 4th addition and understand there is a new edition coming out in 2020.&amp;nbsp; This is a reference book and not a how to book but I have never used a programing book as much as I have this one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2019 19:55:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-call-a-web-service-from-python/m-p/175788#M13520</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2019-09-03T19:55:57Z</dc:date>
    </item>
  </channel>
</rss>

