Invalid header error, need to know how to set header for kiteconnect

avijitkt
avijitkt edited February 2020 in Python client
Hi,

I am getting the following error when trying to fetch ticker.
Till session generation no issues found. kindly help.


File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/kiteconnect/connect.py", line 595, in ltp
return self._get("market.quote.ltp", {"i": ins})
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/kiteconnect/connect.py", line 817, in _get
return self._request(route, "GET", params)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/kiteconnect/connect.py", line 865, in _request
raise e
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/kiteconnect/connect.py", line 862, in _request
proxies=self.proxies)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/http/client.py", line 1293, in _send_request
self.putheader(hdr, value)
File "/Users/avijitmukherjee/opt/anaconda3/lib/python3.7/http/client.py", line 1230, in putheader
raise ValueError('Invalid header value %r' % (values[i],))
ValueError: Invalid header value b'token ....
Tagged:
  • rakeshr
    @avijitkt
    ValueError: Invalid header value b'token
    Can you re-check, if you are assigning correct access_token and api_key ticket object?
    May be post complete WebSocket code here.
  • avijitkt
    @rakeshr I was able to solve it. When I was reading the access token was coming with /n at the end.
    I stripped it off.
    It works now. Many thanks for responding
This discussion has been closed.