【问题标题】:How to connect to a JDA server from Python如何从 Python 连接到 JDA 服务器
【发布时间】:2019-03-01 04:19:30
【问题描述】:

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

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

执行请求并获得会话密钥值。还使用 session-key 执行了命令,但输出没有得到反映。

调用此特定命令以使用请求正文作为登录。

<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>

我能够成功登录并得到响应

<?xml version="1.0" encoding="UTF-8"?>
<moca-response>
    <session-id></session-id>
    <status>0</status>
    <moca-results>
        <metadata>
            <column name="usr_id" type="S" length="0" nullable="true"/>
            <column name="locale_id" type="S" length="0" nullable="true"/>
            <column name="addon_id" type="S" length="0" nullable="true"/>
            <column name="cust_lvl" type="I" length="0" nullable="true"/>
            <column name="session_key" type="S" length="0" nullable="true"/>
            <column name="pswd_expir" type="I" length="0" nullable="true"/>
            <column name="pswd_expir_dte" type="D" length="0" nullable="true"/>
            <column name="pswd_disable" type="I" length="0" nullable="true"/>
            <column name="pswd_chg_flg" type="O" length="0" nullable="true"/>
            <column name="pswd_expir_flg" type="O" length="0" nullable="true"/>
            <column name="pswd_warn_flg" type="O" length="0" nullable="true"/>
            <column name="srv_typ" type="S" length="0" nullable="true"/>
            <column name="super_usr_flg" type="O" length="0" nullable="true"/>
            <column name="ext_ath_flg" type="O" length="0" nullable="true"/>
        </metadata>
        <data>
            <row>
                <field>SUPER</field>
                <field>US_ENGLISH</field>
                <field>3pl,WM,SEAMLES,3pl</field>
                <field>10</field>
                <field>;uid=SUPER|sid=b6698786-85dc-41ec-9e54-c0d8f99b5cbf|dt=jttyorn7|sec=ALL;Hz1biv4HuD_Uq3g.R9QtCfwjQ0</field>
                <field null="true"></field>
                <field null="true"></field>
                <field>6008</field>
                <field>0</field>
                <field>0</field>
                <field>0</field>
                <field>DEVELOPMENT</field>
                <field>1</field>
                <field>0</field>
            </row>
        </data>
    </moca-results>
</moca-response>

根据 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>

但变化没有得到反映。

我还在查询中尝试了另一个 moca 命令..

<query>
    list warehouses
</query>

即使它执行了如何取回准确的输出

【问题讨论】:

    标签: java python


    【解决方案1】:

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

    我将带有请求标头'Content-Type': 'application/moca-xml' 的XML 发布到&lt;host&gt;:&lt;port&gt;/service。下面的示例 XML 正文将运行 list user tables MOCA 命令。

    <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 正文。

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

    【讨论】:

    • 你能解释一下吗..这是我们必须提出的发布请求吗?还有你在哪里指定'list user tables' moca 命令。 @wbarton
    • 是的,这是一个发布请求。 'list user tables' 命令在 MOCA 服务器上可用,任何命令都可以通过将其添加到 XML 中的 &lt;query&gt; 来传递给服务器。
    • 所以其余的端点将是 host:port/service 这里的服务是什么?它是硬编码的静态值吗
    • 是的,service 是一个静态值。
    • 会话密钥作为登录请求响应的一部分返回,我已使用所需的 XML 正文更新了答案。
    【解决方案2】:

    您可以使用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')
    

    希望对你有帮助...

    【讨论】:

    • 按照我的阅读方式,OP 有一个运行 JDA(discord api 的包装器)的机器人,并且想从他的 python 脚本远程控制机器人——而不是在 python 中运行机器人本身。
    猜你喜欢
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 2019-11-15
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多