Text

Text Websocket Recognition Not working

Hi , 

I am trying to use continue recognition   but after connection i am not getting second request .

Please let me know if there is any problem in my code or api has been change 

Thanks 


import websockets
import asyncio
import json
async def hello():
    async with websockets.connect(‘wss://cloud.myscript.com/api/v3.0/recognition/ws/text’) as websocket:
        data = {
          “type”:“applicationKey”,
          “applicationKey”:“XXXXXXXX"
        }
        await websocket.send(json.dumps(data))
        greeting = await websocket.recv()
        print(greeting)
        data2 = {‘textParameter’: {‘textInputMode’: ‘CURSIVE’, ‘resultDetail’: ‘CHARACTER’, ‘textProperties’: {‘textCandidateListSize’: 3, ‘wordCandidateListSize’: 3, ‘characterCandidateListSize’: 1}, ‘language’: ‘en_US’}, ‘inputUnits’: [{‘textInputType’: ‘MULTI_LINE_TEXT’, ‘components’: [{‘type’: ‘stroke’, ‘x’: [1, 2, 3], ‘y’: [1, 2, 3]}]}], ‘containerId’: ‘form1’, ‘containerType’: ‘FORM’, ‘type’: ‘start’}
        websocket.send(json.dumps(data2))
        greeting = await websocket.recv()
        print(greeting)

asyncio.get_event_loop().run_until_complete(hello())

1)I am getting success response while establishing connection. But when I make second request i am not getting response. I am not getting any error message. 

{
"type":"init",
"result":"success"
}

2)  I have disabled HMAC from Myscript dashboard. 


Dear Mukesh Kumar,

Thank you for contacting us and provided us with further information.

There is a "await" missing when sending your second message and this is probably the reason why you don't get neither an error nor a response.

Line 35 in your code should thus be updated to :

await websocket.send(json.dumps(data2))

We would like to draw your attention that the V3 API you are using is now deprecated and we therefore recommend you using the V4 API, especially if you are starting a new project.

Regards,

Gwenaëlle

Hi ,

Thank you very much for reply.

Now I am receiving valid response but socket get closed after one request.   

#same code as above 

#First request
await websocket.send(json.dumps(data2))
greeting = await websocket.recv()
print(greeting)
#second request
await websocket.send(json.dumps(data2))
greeting = await websocket.recv()
print(greeting)
 

 I am getting following Error while sending second request for same data:

{“type”:“error”,“error”:{“result”:{“error”:“SessionStateException”,“message”:“another text session already exists. You have to reset the current session or open another websocket.“,”status”:“error”}}}


Thanks 



Dear Mukesh Kumar,


In order to take the most advantage of the APIs, we recommend you reading carefully the following section https://developer.myscript.com/docs/interactive-ink/1.3/web/overview/http-rest-or-websocket/

so that you can choose between REST and WebSockets APIs.


If you want to perform some server to server calls, Websocket is not the best choice, as Websocket is more adapted to the case when you are looking for interactivity with a client working in graphical mode.


If you have already collected set of strokes and want to recognize the digital content, then REST is the appropriate choice.


Regards,


Gwenaëlle



Login or Signup to post a comment