Hi Rushabh,
On Monday, January 21, 2013 3:30:54 PM UTC+1, rushabh wrote:
Jonathan,Your second approach is correct. You need to do a POST. You are not able send 2 items because of the URL limit in GET.From the traceback, the parameters are not getting mapped correctly - can you debug the POST a bit?I am sure you are pretty close to the solution.best,RushabhHi. 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 metupdate(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 mainupdate(server, rows);File “…\updateqty.py”, line 50, in update“doclist”: json.dumps(doclist)File “…\updateqty.py”, line 62, in requestresponse = requests.post(server, cookies = {“sid”: sid}, params=params)File “C:\Python27\lib\site-packages\requests\api.py”, line 87, in postreturn request(‘post’, url, data=data, **kwargs)File “C:\Python27\lib\site-packages\requests\api.py”, line 44, in requestreturn session.request(method=method, url=url, **kwargs)File “C:\Python27\lib\site-packages\requests\sessions.py”, line 279, in requestresp = 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 sendr = adapter.send(request, **kwargs)File “C:\Python27\lib\site-packages\requests\adapters.py”, line 222, in sendr.contentFile “C:\Python27\lib\site-packages\requests\models.py”, line 550, in contentself.content = bytes().join(self.itercontent(CONTENT_CHUNK_SIZE)) or bytes()File “C:\Python27\lib\site-packages\requests\models.py”, line 496, in generatechunk = self.raw.read(chunk_size)File “C:\Python27\lib\site-packages\requests\packages<wbr>urllib3\response.py”, line 148, in readreturn self._fp.read(amt)File “C:\Python27\lib\httplib.py”, line 561, in reads = self.fp.read(amt)File “C:\Python27\lib\httplib.py”, line 1298, in readreturn s + self._file.read(amt - len(s))File “C:\Python27\lib\socket.py”, line 380, in readdata = self._sock.recv(left)socket.error: [Errno 10054] An existing connection was forcibly closed by the remote hostIf 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<wbr>", line 159, in handle\n execute_cmd(cmd)\n File \“…/lib/webnotes/handler.py<wbr>", line 191, in execute_cmd\n ret = call(method, webnotes.form_dict)\n File \”…/lib/webnotes/handler.py<wbr>", 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.Jonathan,The way to do this would be to first get, update and push.You can send the list of dicts (we call it a doclist) via a POST request. It should work - where are you getting stuck? Is there a specific error message?- RushabhW: https://erpnext.com
T: @rushabh_mehtaOn 17-Jan-2013, at 12:49 AM, Jonathan <ir...@gmail.com> wrote:Thanks for the reply. What we are trying to do is update a complex doctype from a script--specifically we are trying to update a BOM--that is to say, update some subset of BOM Items for a given BOM. The first approach was to try get_doc on an individual BOM Item, passing in the parent BOM name and the item_code of the particular Bom Item as parameters. Various experiments along those lines got us the response that get takes 2 arguments and only 1 is given.The next approach was to read the entire BOM using get_doc (this works fine), modify the fields in question, then call update. But this puts the entire pile of json into the url. Experiments trying to move the data into the body of the POST didn't get anywhere.Can you suggest a way forward?Thanks very much.- j
On Saturday, January 12, 2013 4:28:50 AM UTC+1, rushabh wrote:Jonathan, you have to "get" the customer after save, rename it and save gain. The system will only save if the incoming record's "modified" property matches with the one in the database to maintain version conflicts.
Sent from mobileHi, sorry, me again.We are trying to create--and optionally update--a Customer doctype based on the script that started this thread. We are able to create a customer, but so far we have not been able to create a customer where the customer_name is different from the name. In other words we have a unique name for the Customer ("johndoe123"), which is what we want the doctype to be referenced by, but we want the customer's name to be "John Doe". Once the Customer doctype is created we can change the customer name using the ERPNext API, but we were unable to create the customer that way or update it thereafter. In particular, the update function returns a message that says "Document has been modified after you have opened it."Could you point us in the right direction?Thanks.
On Monday, January 7, 2013 3:47:39 PM UTC+1, Jonathan wrote:Thanks for the suggestion. The problem seems to be the weird parameter-doubling from the 'requests' module. Now the login is working...- j
On Monday, January 7, 2013 3:19:45 PM UTC+1, rushabh wrote:The test runs fine on my setup. I think your installation may be messed up.What do you get when you run that from the browser?
Sent from mobileHere's the redacted url returned from response.get(). Odd that all the params are doubled.https://{server}/server.py?pwd={password}&cmd=login&usr={user}&pwd={password}&cmd=login&usr={user}We are using the sample code llinked to earlier in the forum, only changing the server, user, and password parameters at the top (we also changed response.json.get() to response.json().get()--the code wouldn't work otherwise).Thanks.
On Monday, January 7, 2013 2:43:00 PM UTC+1, rushabh wrote:Can you post the entire url? I think you need to pass login id and password as the url parametersFor example you can login via:server.py?cmd=login&usr=Administrator&pwd=adminIf you are passwords are correctly set.On Mon, Jan 7, 2013 at 6:40 PM, Amin Zayani <za...@gmail.com> wrote:
Thanks for the quick reply. We should have thought to test the simplest server.py url. We get back the following json in response to the login.
{u'message': u'', u'exc': u'"Traceback (innermost last):\\n File \\"../lib/webnotes/handler.py\\", line 159, in handle\\n execute_cmd(cmd)\\n Fil
e \\"../lib/webnotes/handler.py\\", line 176, in execute_cmd\\n method = get_method(cmd)\\n File \\"../lib/webnotes/handler.py\\", line 218, in ge
t_method\\n method = globals()[cmd]\\n KeyError: u\\"[\'login\', \'login\']\\"\\n"'}
Any suggestions?
Thanks again.PS: my colleague Jonathan will join this thread
On Monday, January 7, 2013 1:10:56 PM UTC+1, rushabh wrote:Amin,Thanks for making the 3rd party API script available. We are newbies at ERPNext, so please excuse the following questions if the answers should be obvious.
In our tests using the sample code fromhttps://github.com/webnotes/wnframework/blob/master/webnotes/utils/webclient.py, we have not been able to get past login--we get a 404 response. We are trying variations of "http://{our local erpnext server}/webnotes/erpnext_master/public/server.py" as the server address. Our ERPNext is installed simply on a Ubuntu 12.10 virtual machine on a local server and is also accessible outside our LAN through a subdomain of our site, so we were trying, for example, "http://{our local erpnext server}/public/server.py". Can you give us any hints about what the url should be? (We also tried "client.py" instead of "server.py").
Don't use /public/server.py --- just use {local erpnext server}/server.pySince all requests are passed via server.py (and this should be accessible via your browser). So set "server" to that url (which is server.py replaced by app.html)We are also not entirely certain that we have updated ERPNext correctly in order to install the correct "client.py" file into the proper location. Can you tell us how to ascertain whether we have the correct file and it's in the expected place? Once it's in the right place do we need to set any permissions? (because the repository updated is webnotes framework and we only update our ERPNext repository version)
the webclient.py file can be anywhere because it accesses the system via http requests.Also webclient.py is a template and you can use that code to access data from anywhere.
Thanks.
On Monday, January 7, 2013 6:08:22 AM UTC+1, rushabh wrote:Also updated webclient.py:On Mon, Jan 7, 2013 at 10:32 AM, Rushabh Mehta <rm...@gmail.com> wrote:
Just updated client.py withwebnotes.client.getpass "doctype" and "name" as parametersexample:cmd=webnotes.client.get&doctype=[doctype]&name=[name]you will get a JSON object with a list of main record and the child records (if any)–On Fri, Jan 4, 2013 at 7:42 PM, Amin Zayani <za...@gmail.com> wrote:
Great!Any chance you add a "read" method to fetch data from ERPNext? And include a simple example for fetching some doctype?Thanks
On Wednesday, December 19, 2012 12:41:39 PM UTC+1, rushabh wrote:Dear all,Since there has been some interest off and on for this, I have created a very alpha level script for those who are interested to integrate other 3rd party tools into ERPNext.The schematics are very simple and the script is pretty self-expalnatory.Please ping us on the Developer Forum if you have any difficulty. If you are able to integrate any app, please share with us so other users can also benefit.best,Rushabh–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to er…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+unsubscr…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/yzLMPR9UcxsJ.For more options, visit https://groups.google.com/groups/opt_out.
Twitter: @rushabh_mehta--Twitter: @rushabh_mehta–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to erpnext-dev…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+unsubscr…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/QpP1CwrCuW8J.
For more options, visit https://groups.google.com/groups/opt_out.
–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to er…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/9sfw-iCSHTkJ.--Twitter: @rushabh_mehta–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to er…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/AtBNp4DGZjsJ.
For more options, visit https://groups.google.com/groups/opt_out.
–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to er…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/d1YRSsSA8U8J.
For more options, visit https://groups.google.com/groups/opt_out.
–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to er…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/sso_-D03AMEJ.
For more options, visit https://groups.google.com/groups/opt_out.
–
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
To post to this group, send email to erpnext-dev…@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/BiY2q-sq-2gJ.
For more options, visit https://groups.google.com/groups/opt_out.
–
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To post to this group, send email to er...@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/NDrHqRjqDQEJ.
For more options, visit https://groups.google.com/groups/opt_out.