如何从Python连接到JDA服务器

2024-09-21 00:51:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个带有连接细节的JDA服务器。我必须从python程序连接到这个JDA服务器并执行MOCA命令。我已经搜索过了,到目前为止还没有找到任何关于这个的文档。在

找到了一些jar文件,但没有发现Python。我的python客户端应用程序必须连接到JDA并执行命令。在

执行请求并获取会话键值。也使用会话键执行了命令,但输出没有得到反映。在

调用此特定命令以请求主体身份登录。在

<moca-request autocommit="True">
  <environment>
    <var name="USR_ID" value="super"/>
  </environment>
  <query>login user where usr_id = 'super' and usr_pswd = 'super'</query>
</moca-request>

我能够成功登录,并得到的回应为

^{pr2}$

根据xml响应,我将会话密钥设置为;uid=SUPER | sid=b6698786-85dc-41ec-9e54-c0d8f99b5cbf | dt=jttyorn7 | sec=ALL;Hz1biv4HuD_Uq3g.R9QtCfwjQ0,并尝试执行这些命令。在

我就是这样执行命令的

<moca-request autocommit="True">
  <environment>
    <var name="USR_ID" value="super"/>
    <var name="SESSION_KEY" value=";uid=SUPER|sid=b6698786-85dc-41ec-9e54-c0d8f99b5cbf|dt=jttyorn7|sec=ALL;Hz1biv4HuD_Uq3g.R9QtCfwjQ0"/>
    <var name="LOCALE_ID" value="US_ENGLISH"/>
    <var name="MOCA_APPL_ID" value="MYAPP"/>
  </environment>
 <query>
     create record where table = 'alt_prtmst' and prtnum = 'TEST1' and alt_prtnum = 'TEST123' and alt_prt_typ = 'SAP' and prt_client_id = '----' </query>
</moca-request>

命令执行时没有任何错误,我也得到了响应。在

<?xml version="1.0" encoding="UTF-8"?>
<moca-response>
    <session-id></session-id>
    <status>0</status>
</moca-response>

但没有得到反映。在

我还在query中尝试了另一个moca命令。。在

<query>
    list warehouses
</query>

即使它执行了如何获得准确的输出


Tags: andname命令服务器idenvironmentvaluerequest
2条回答

我已经解释了您的问题,即您正在尝试连接到JDA(WMS)实例。 我在NodeJs中创建了一个连接到实例并执行MOCA命令的应用程序。在

我将带有请求头'Content-Type': 'application/moca-xml'的XML发布到<host>:<port>/service。下面的示例XML主体将运行list user tablesMOCA命令。在

<moca-request autocommit="True">
  <environment>
    <var name="USR_ID" value="..."/>
    <var name="SESSION_KEY" value="..."/>
    <var name="LOCALE_ID" value="EN-GB"/>
    <var name="MOCA_APPL_ID" value="MYAPP"/>
  </environment>
  <query>list user tables</query>
</moca-request>

SESSION_KEY可以从登录请求的响应中获取,XML正文如下。在

^{pr2}$

可以使用this从python连接到不一致服务器。示例如下:

import discord
from discord.ext import commands
import random

description = '''An example bot to showcase the discord.ext.commands extension
module.

There are a number of utility commands being showcased here.'''
bot = commands.Bot(command_prefix='?', description=description)

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('   ')

@bot.command()
async def add(left : int, right : int):
    """Adds two numbers together."""
    await bot.say(left + right)

@bot.command()
async def roll(dice : str):
    """Rolls a dice in NdN format."""
    try:
        rolls, limit = map(int, dice.split('d'))
    except Exception:
        await bot.say('Format has to be in NdN!')
        return

    result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
    await bot.say(result)

@bot.command(description='For when you wanna settle the score some other way')
async def choose(*choices : str):
    """Chooses between multiple choices."""
    await bot.say(random.choice(choices))

@bot.command()
async def repeat(times : int, content='repeating...'):
    """Repeats a message multiple times."""
    for i in range(times):
        await bot.say(content)

@bot.command()
async def joined(member : discord.Member):
    """Says when a member joined."""
    await bot.say('{0.name} joined in {0.joined_at}'.format(member))

@bot.group(pass_context=True)
async def cool(ctx):
    """Says if a user is cool.

    In reality this just checks if a subcommand is being invoked.
    """
    if ctx.invoked_subcommand is None:
        await bot.say('No, {0.subcommand_passed} is not cool'.format(ctx))

@cool.command(name='bot')
async def _bot():
    """Is the bot cool?"""
    await bot.say('Yes, the bot is cool.')

bot.run('token')

希望对你有帮助。。。在

相关问题 更多 >

    热门问题