mercredi 3 février 2021

Python web service pasiing arraylist

I want to write a web service with python that is getting data from another web service that is written in Java.

The method that i want to get the data from service is public List programsByIdList(List IdList):

DtoIdName is a class and has two values; id(Long) and name(String)

this web service is written with Java so the List is Java.util.List ...

when i write the web service in python it is like that...

import requests
import json
from bs4 import BeautifulSoup as bs 
import flaskfrom 
flask import Flask, jsonify
from flask import make_response
from flask import requestimport xmltodict

TEST = 'http://192.166.5.0/YService/RadioService/'

app = flask.Flask(__name__)
app.config["DEBUG"] = True
headers = { 
     'Accept': 'application/xml',
}

#programsByIdList
@app.route('/programsByIdList', methods=['GET'])

def programsByIdList(): 
idList= [10262,10498] 
arguments = {'arg0[]': idList}

print(arguments) 
response = requests.get(TEST+'programsByIdList',headers=headers, params=arguments) 
soapXML = response.content.decode("utf-8") 
soapSoup =bs(soapXML, "xml") 
programNames = soapSoup.find_all('name') 
data = response 
xpars = xmltodict.parse(data.text) 
json1 = json.dumps(xpars,indent=4,ensure_ascii=False) 

for ad in programNames: 
    print(ad.get_text()) 
    return json1

@app.route('/', methods=['GET'])
def home(): 
    return "<h1>Service</h1><p> Service methods.</p>"

print(programsByIdList())
app.run()

When i run my python code, it says { "soap:Envelope": { "@xmlns:soap": "https://ift.tt/sVJIaE", "soap:Body": { "soap:Fault": { "faultcode": "soap:Server", "faultstring": "argument type mismatch while invoking public abstract java.util.List eradyo.akis.service.AkisService.programsBySezonIdList(java.util.List) with params [10262]." } } } }

i think i am confused with written python service with java.List arguments...is there a way to solve my problem... how to pass the Arraylist to python request..

thank you very much....




Aucun commentaire:

Enregistrer un commentaire