Python错误将值“ AddmissionGuid”转换为System.GUID

时间:2018-10-02 08:37:13

标签: python json signalr uuid guid

我正在从请求中接收数据,如下所示

[
  {
    "Info": {
      "SoftwareVersion": "111",
      "IpAddress": "111.111.11",
      "DeviceName": "1111222",
      "Type": "Tablet"
    },
    "DeviceIdentity": "Identity",
    "AdmissionGuid": "db128362-f942-47fb-b18e-c073aa03b95d",
    "UserId": "8c7be5ac-9f2e-42aa-8f17-4e935a85eff3",
    "ConnectionId": "f78f544e-0780-4b07-87ec-d4edbe4cb522",
    "PairingId": null
  }
]

然后我试图在python中解析它,一切正常,我得到了预期的值,但出现以下错误,我试图将其转换为Object,String,Hex,但没有任何效果

  

将值“ AdmissionGuid”转换为System.GUID时出错

Python脚本

from requests import Session
from signalr import Connection
import threading, time, json, logging
import urllib.request
import requests
import uuid


GetPatientID = requests.get('http://example-url.com/api/json')



 data = GetAdmissionID.json()
print (type(data))

AdmissionGuid= uuid.UUID(data[0]["AdmissionGuid"])
print (type(AdmissionGuid))

UserID = "8c7be5ac-9f2e-42aa-8f17-4e935a85eff3"
softwareVersion = "111"
IpAddress = "111.111.11"
machineName = "1111222"
DeviceType = "Tablet"
pairingId = "null"
def __init__(self, cli):
    self.cli = cli
    logging.info("registered the cli (main thread)")




with Session() as session:
    connection = Connection("http://example-url.com/signalr", session)
    print(connection)
    logging.info("got the connection")
    presenceservice = connection.register_hub('ClientRegistration')
    logging.info("got the hub")

    connection.start()
    def get_data(notificaition):
        print("Recived something?: ", notificaition)
    def print_error(error):
        print('error: ', error)
    connection.error += print_error
    presenceservice.server.invoke('IdentifyClient', 'devideIdentity', 'softwareVersion', 'ipAddress',
                                          'machineName', 'deviceType', 'patientAdmissionGuid', 'patientId', 'pairingId')
    key = input("Press E\n")
    if key == 'e':
        connection.wait(1)

        presenceservice.client.on('Notification', get_data)

        print ('Nothing Happned')



    connection.wait(30)

还有日志

<class 'list'>
<class 'uuid.UUID'>
Press E
e
error:  Error converting value "AdmissionGuid" to type 'System.Guid'.

注意:我还使用Singal R libary调用C#Hub来注册客户端。

AdmissionGuid是使用GUID库

在C#中生成的

有没有办法使用python?

我已经12看过了,但这不能解决我的问题

EDIT C#函数我正在用单个R调用

IdentifyClient(string devideIdentity, string softwareVersion, string ipAddress, string machineName, string deviceType, Guid AdmissionGuid, Guid UserID, string pairingId)

1 个答案:

答案 0 :(得分:1)

我已经解决了我的问题,我在使用String而不是变量来调用IdentifyClient()函数,这是一个简单的解决方法。

更改了此

presenceservice.server.invoke('IdentifyClient', 'devideIdentity', 'softwareVersion', 'ipAddress',
                                          'machineName', 'deviceType', 'patientAdmissionGuid', 'patientId', 'pairingId')

对此

presenceservice.server.invoke('IdentifyClient', devideIdentity, softwareVersion, ipAddress,
                                          machineName, deviceType, patientAdmissionGuid, patientId, pairingId)