<?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 Re: Need Python 3 code snippet to call SAP Leonardo ML ReST API prodimgclassifier in Artificial Intelligence Forum</title>
    <link>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559049#M83</link>
    <description>&lt;P&gt;Hi Auro,&lt;/P&gt;
  &lt;P&gt;If you get rid of the 'Content-Type':'multipart/form-data' in the header it should work:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;import requests
url = "https://sandbox.api.sap.com/ml/prodimgclassifier/inference_sync"
headers = {'APIKey': &amp;lt;your_API_key&amp;gt;, 'Accept': 'application/json'}
files = {'files': open('desert.jpg', 'rb')}
response = requests.post(url, files=files, headers=headers)
print(response.text)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Sep 2017 11:29:57 GMT</pubDate>
    <dc:creator>christianmathias_mueller</dc:creator>
    <dc:date>2017-09-18T11:29:57Z</dc:date>
    <item>
      <title>Need Python 3 code snippet to call SAP Leonardo ML ReST API prodimgclassifier</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559048#M82</link>
      <description>&lt;P&gt;Here's my NON-WORKING version using Python library requests. &lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;import requests
import json
import logging

try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

headers = {'APIKey': 'your API Key',
           'Accept': 'application/json',
           'Content-Type': 'multipart/form-data'}

params = {'files' : 'Desert.jpeg'}
data = {'files' : 'Desert.jpg'} #  url encoded
# data = json.dumps(data) # flat
files = {'files' : open('Desert.jpg', 'rb')}

r = requests.post("https://sandbox.api.sap.com/ml/prodimgclassifier/inference_sync",
                  # params=params,
                  # data=data,
                  headers=headers,
                  files=files)
print('\n------------------\n')
print(r.text)&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Response is:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;"error_description": "This service requires at least 1 file. Please put your file(s) into the `fil&lt;BR /&gt;es` field of the POST request",&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Feb 2024 02:09:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559048#M82</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2024-02-04T02:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python 3 code snippet to call SAP Leonardo ML ReST API prodimgclassifier</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559049#M83</link>
      <description>&lt;P&gt;Hi Auro,&lt;/P&gt;
  &lt;P&gt;If you get rid of the 'Content-Type':'multipart/form-data' in the header it should work:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;import requests
url = "https://sandbox.api.sap.com/ml/prodimgclassifier/inference_sync"
headers = {'APIKey': &amp;lt;your_API_key&amp;gt;, 'Accept': 'application/json'}
files = {'files': open('desert.jpg', 'rb')}
response = requests.post(url, files=files, headers=headers)
print(response.text)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 11:29:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559049#M83</guid>
      <dc:creator>christianmathias_mueller</dc:creator>
      <dc:date>2017-09-18T11:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python 3 code snippet to call SAP Leonardo ML ReST API prodimgclassifier</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559050#M84</link>
      <description>&lt;P&gt;Works! Thank you, @  &lt;/P&gt;
  &lt;P&gt; &lt;A href="https://answers.sap.com/users/207855/christianmathiasmueller.html"&gt;Christian Mathias Mueller&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 04:48:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/need-python-3-code-snippet-to-call-sap-leonardo-ml-rest-api/m-p/559050#M84</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-09-21T04:48:16Z</dc:date>
    </item>
  </channel>
</rss>

