question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Following redirects does not work in es-py

See original GitHub issue

I tried my best to follow the documentation and code to figure out how to enable redirects for an ES client, but keep getting an HTTP 302 response for my request. Here is my code:

headers={'connection': 'keep-alive', 'redirects': True}
es = Elasticsearch([{'host': cluster, 'port': 80}], http_auth=(user, secret), scheme='http', headers=headers)
res = es.exists(index=myIndex, doc_type='test', id='ABCDEF1234')

Here is the error message I see:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/x-9GQQSZlO/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 76, in _wrapped
    return func(*args, params=params, **kwargs)
  File "~/x-9GQQSZlO/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 357, in exists
    doc_type, id), params=params)
  File "~/x-9GQQSZlO/lib/python2.7/site-packages/elasticsearch/transport.py", line 314, in perform_request
    status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
  File "~/x-9GQQSZlO/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 180, in perform_request
    self._raise_error(response.status, raw_data)
  File "~/x-9GQQSZlO/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.TransportError: TransportError(302, u'')

Based on the code in es-py GitHub under connection/http_requests.py, headers set this way below should have worked. I tried these variations below but without success.

headers={'connection': 'keep-alive', 'redirects': True}
headers={'connection': 'keep-alive', 'redirects': 'true'}

What am I missing ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fxdgearcommented, Feb 14, 2019

@MarcDAFrame It’s built into the library already all you have to do is instantiate your connection using the requests transport class. https://elasticsearch-py.readthedocs.io/en/master/transports.html#transport-classes

1reaction
fxdgearcommented, May 31, 2018

@jarajapu Thanks for the issue.

Where did you find documentation about that header?

re using scheme I don’t think you should really worry about that. Just instantiate the object with a string of your cluster url.

es = Elasticsearch("https://mycluster.domain.com:9200", http_auth=('username', 'password'))
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why browser do not follow redirects using XMLHTTPRequest ...
Simple GET requests using CORS are working just fine in Chrome and Firefox. Some method accept data via POST and return 303 code...
Read more >
Postman always follows redirects, ignores setting ... - GitHub
I have moved to Postman for Linux which solved the problem for me. ... Settings > Interceptor > Automatically follow redirects is off....
Read more >
OWA redirection doesn't work after installing November 2021 ...
Exchange Server admins can use the redirect rule to modify the redirect URL so that the error does not appear to users.
Read more >
Redirections in HTTP - MDN Web Docs - Mozilla
HTTP redirects are the best way to create redirections, but sometimes you don't have control over the server. In that case, try a...
Read more >
Using redirects - AWS Amplify Hosting
404 redirects occur when a request points to an address that doesn't exist. The destination page of a 404 is displayed instead of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found