代码之家  ›  专栏  ›  技术社区  ›  AutoTester213

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

  •  3
  • AutoTester213  · 技术社区  · 6 年前

    我收到如下请求的数据

    [
      {
        "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 在C#中使用GUID库生成,

    有办法进入python吗?

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

    编辑 C#我正在用信号R调用函数

    IdentifyClient(string devideIdentity, string softwareVersion, string ipAddress, string machineName, string deviceType, Guid AdmissionGuid, Guid UserID, string pairingId)
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   AutoTester213    6 年前

    我已经解决了我的问题,我正在调用 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)