Hi. I am still unable to get update to work and am asking two specific questions.
1. We have a BOM doctype which contains a number of individual BOM Item doctypes. Is it possible to read and update an individual BOM Item from a BOM doctype, or must one read the entire BOM and update the whole thing at once? So far I have only managed to read the entire BOM, but not an individual BOM Item.
2: Since I cannot so far read individual BOM Items, I am trying to update the entire BOM doctype. My update script works successfully if the BOM contains only a single BOM Item, but fails if there are two BOM Items. Why is that?
My script uses the same functions for get_doc(), login(), update(), etc. that you posted here: https://github.com/webnotes/wnframework/blob/master/webnotes/utils/webclient.py. In the original update function, the doclist is added to the params argument of requests.post(), which means the entire doclist is added to the request url. Specifically, I am doing the following:
doc = get_doc("BOM", bom)
rows = doc.json().get("message")
for row in rows
# change Qty if a certain condition is met
update(rows)
If there is one BOM Item in the BOM, the update is successful. With two or more Bom Items, I get the following traceback:
Traceback (most recent call last):
File "...\updateqty.py", line 187, in <module>
main()
File "...\updateqty.py", line 182, in main
update(server, rows);
File "...\updateqty.py", line 50, in update
"doclist": json.dumps(doclist)
File "...\updateqty.py", line 62, in request
response = requests.post(server, cookies = {"sid": sid}, params=params)
File "C:\Python27\lib\site-packages\requests\api.py", line 87, in post
return request('post', url, data=data, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 374, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 222, in send
r.content
File "C:\Python27\lib\site-packages\requests\models.py", line 550, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "C:\Python27\lib\site-packages\requests\models.py", line 496, in generate
chunk = self.raw.read(chunk_size)
File "C:\Python27\lib\site-packages\requests\packages\urllib3\response.py", line 148, in read
return self._fp.read(amt)
File "C:\Python27\lib\httplib.py", line 561, in read
s = self.fp.read(amt)
File "C:\Python27\lib\httplib.py", line 1298, in read
return s + self._file.read(amt - len(s))
File "C:\Python27\lib\socket.py", line 380, in read
data = self._sock.recv(left)
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host
If instead I try to extend the update to use the "data" argument (which puts the data into the body of the post rather than the url), something like:
response = requests.post(server, cookies = {"sid": sid}, params=params, data=data)
where params= {
"cmd": "webnotes.client.save"
}
and data= {
"doclist": json.dumps(doclist)
}
I get the following result from ERPNext:
{u'message': u'', u'exc': u'"Traceback (innermost last):\\n File \\"../lib/webnotes/handler.py\\", line 159, in handle\\n execute_cmd(cmd)\\n File \\"../lib/webnotes/handler.py\\", line 191, in execute_cmd\\n ret = call(method, webnotes.form_dict)\\n File \\"../lib/webnotes/handler.py\\", line 210, in call\\n return fn(**newargs)\\n TypeError: save() takes exactly 1 argument (0 given)\\n"'}
Can you suggest the right approach for updating either individual BOM Items or the entire BOM?
Thank you for your help.