0

I am trying to connect to a remote gremlin server which requires uname/password authentication over ssl using gremlin_python. This is a snippet of the code I am using:

conf = yaml.load(stream, Loader=yaml.SafeLoader)
print(conf) 
g = traversal().withRemote(DriverRemoteConnection(**conf))

The contents of the conf dict is:

{'url': 'wss://my-url.com:port', 'username': 'admin', 'password': '**', 'traversal_source': 'graph_traversal'}

I am able to connect to the same server from gremlin console using a conf/my.properties file that looks like

  hosts: [my-url.com]
  port: port
  username: admin
  password: *
  connectionPool: { enableSsl: true }
  serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}

My attempts to connect from python is resulting in a E tornado.httpclient.HTTPError: HTTP 502: Bad Gateway. I know that my connection url itself is correct, I am able to connect from the gremlin-console as well as send scripts over https. I have been trying to look at the code here to figure out what is going wrong.

[EDIT:] After looking at this a little deeper, I figured out that you can authenticate with the wss server with an auth token in the header. I was able to test this out directly with websockets. Is there any way I can pass along a parameter in the header when I open a DriverRemoteConnection for gremlin_python?

Max Arbiter
  • 318
  • 4
  • 18

1 Answers1

2

Replace {{ end_point }}, {{ username }}, {{ password }} as your real value:

from tornado import httpclient

my_req = httpclient.HTTPRequest('wss://{{ end_point }}:8182/gremlin', headers={"Authorization": "Token AZX ..."})

DriverRemoteConnection(my_req, 'g', username="{{ username }}", password="{{ password }}")
sel-fish
  • 4,308
  • 2
  • 20
  • 39
  • This is pretty much what I am trying now. Is there an option to pass http header parameters to the wss server through the `DriverRemoteConnection`? The graph service I am using is expecting a token to authenticate. – Max Arbiter Apr 02 '19 at 11:26
  • @MaxArbiter what http header you want to pass? – sel-fish Apr 02 '19 at 11:29
  • Thanks for looking in. I was hoping to pass `header='{Authorization: Token AZX....}'` I was able to authenticate using this when I tested directly with python `websocket` s – Max Arbiter Apr 02 '19 at 11:39
  • @MaxArbiter the first parameter of DriverRemoteConnection.__init__ could be an instance of HTTPRequest, refer to the updated answer – sel-fish Apr 02 '19 at 16:01
  • That seems to have done the trick w00t w00t. Thank you very much. – Max Arbiter Apr 03 '19 at 02:16