Due to some technical glitch,the server returned no content probably,so there was no 'content-type' in the headers of the reponse.
So,the requests library gave key error.
You have to retry incase something like this happens.
'HTTP/1.1 500 Internal Server Error\r\n' GeneralException: Enterd Qty cannot be greater than Net qty
Are you sure, the above exception message is from kiteconnect python client? As, we return `quantity` should be a multiple of lot size {lot_size} for invalid qty with HTTP 400.
User-Agent: Kiteconnect-python/4.0.2
you seem to be also on latest python client version.
KeyError Traceback (most recent call last)
C:\Users\user\AppData\Local\Temp/ipykernel_12748/655508613.py in
----> 1 kite.convert_position(exchange='NFO',
2 tradingsymbol='NIFTY22MAYFUT',
3 transaction_type='SELL',
4 position_type='overnight',
5 quantity=-50,
~\anaconda3\lib\site-packages\kiteconnect\connect.py in convert_position(self, exchange, tradingsymbol, transaction_type, position_type, quantity, old_product, new_product)
452 new_product):
453 """Modify an open position's product type."""
--> 454 return self._put("portfolio.positions.convert", params={
455 "exchange": exchange,
456 "tradingsymbol": tradingsymbol,
~\anaconda3\lib\site-packages\kiteconnect\connect.py in _put(self, route, url_args, params, is_json, query_params)
843 def _put(self, route, url_args=None, params=None, is_json=False, query_params=None):
844 """Alias for sending a PUT request."""
--> 845 return self._request(route, "PUT", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
846
847 def _delete(self, route, url_args=None, params=None, is_json=False):
~\anaconda3\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
896
897 # Validate the content type.
--> 898 if "json" in r.headers["content-type"]:
899 try:
900 data = json.loads(r.content.decode("utf8"))
~\anaconda3\lib\site-packages\requests\structures.py in getitem(self, key)
52
53 def getitem(self, key):
---> 54 return self._store[key.lower()][1]
55
56 def delitem(self, key):
KeyError: 'content-type
So,the requests library gave key error.
You have to retry incase something like this happens.
tradingsymbol='NIFTY22MAYFUT',
transaction_type='SELL',
position_type='overnight',
quantity= 50,
old_product='NRML',
new_product='MIS')
error:-
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "PUT /portfolio/positions HTTP/1.1" 500 116
send: b'PUT /portfolio/positions HTTP/1.1\r\nHost: api.kite.trade\r\nUser-Agent: Kiteconnect-python/4.0.2\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: */*\r\nConnection: keep-alive\r\nX-Kite-Version: 3\r\nAuthorization: token XXXXXXXXXX:XXXXXXXXXX\r\nContent-Length: 131\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
send: b'exchange=NFO&tradingsymbol=NIFTY22MAYFUT&transaction_type=SELL&position_type=overnight&quantity=50&old_product=NRML&new_product=MIS'
reply: 'HTTP/1.1 500 Internal Server Error\r\n'
header: Date: Thu, 12 May 2022 07:16:18 GMT
header: Content-Type: application/json
header: Content-Length: 116
header: Connection: keep-alive
header: CF-Cache-Status: DYNAMIC
header: Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
header: Strict-Transport-Security: max-age=15552000; includeSubDomains
header: Server: cloudflare
header: CF-RAY: 70a15e3e9dd88e7e-DEL
---------------------------------------------------------------------------
GeneralException Traceback (most recent call last)
C:\Users\PRINCE~1\AppData\Local\Temp/ipykernel_8552/16661507.py in
----> 1 kite.convert_position(exchange='NFO',
2 tradingsymbol='NIFTY22MAYFUT',
3 transaction_type='SELL',
4 position_type='overnight',
5 quantity= 50,
~\anaconda3\lib\site-packages\kiteconnect\connect.py in convert_position(self, exchange, tradingsymbol, transaction_type, position_type, quantity, old_product, new_product)
452 new_product):
453 """Modify an open position's product type."""
--> 454 return self._put("portfolio.positions.convert", params={
455 "exchange": exchange,
456 "tradingsymbol": tradingsymbol,
~\anaconda3\lib\site-packages\kiteconnect\connect.py in _put(self, route, url_args, params, is_json, query_params)
843 def _put(self, route, url_args=None, params=None, is_json=False, query_params=None):
844 """Alias for sending a PUT request."""
--> 845 return self._request(route, "PUT", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
846
847 def _delete(self, route, url_args=None, params=None, is_json=False):
~\anaconda3\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
911 # native Kite errors
912 exp = getattr(ex, data.get("error_type"), ex.GeneralException)
--> 913 raise exp(data["message"], code=r.status_code)
914
915 return data["data"]
GeneralException: Enterd Qty cannot be greater than Net qty
As, we return
`quantity` should be a multiple of lot size {lot_size}
for invalid qty with HTTP 400. you seem to be also on latest python client version. Re-inspect, all of these values are correct.