How to reset system proxy using pyhton code
Hi, I am using below python code (Python 2.7) to reset the proxy of my Ubuntu (Cent OS 6) system, but I am unable to reset the proxy: Code : import os print "Unsetting http..." os.system("unset http_proxy") os.system("echo $http_proxy") print "http is reset" Output : Unsetting http... http://web-proxy..xxx.net:8080 http is reset Process finished with exit code 0 It should not return ' http://web-proxy..xxx.net:8080 ' in output. I run the same unset command from terminal , then I see that proxy is reset: [trex@sumlnxvm ~]$ unset $HTTP_PROXY [trex@sumlnxvm ~]$ echo $HTTP_PROXY [trex@sumlnxvm ~]$ Please suggest how to reset system proxy using Python Code Regards, Sumit -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting "ValueError: need more than 1 value to unpack" while trying to read a value from dictionary in python
Thanks Chris :) Its working now. Regards, Sumit On Thu, Feb 15, 2018 at 4:55 PM, Chris Warrick <kwpol...@gmail.com> wrote: > On 15 February 2018 at 12:07, Sum J <sjsum...@gmail.com> wrote: > > Below is my code. Here I want to read the "ip address" from s > > > > > > s= ''' > > Power On Enabled = On > > State: connected > > Radio Module: Unknown > > noise: -097 > > signalStrength: -046 > > ip address: 192.168.75.147 > > subnet mask: 255.255.255.0 > > IPv4 address configured by DHCP > > Mac Addr: ac:e2:d3:32:00:5a > > Mode: infrastrastructure > > ssid: Cloudlab > > Channel: 1 > > Regulatory: World Safe > > Authencation: WPA2/PSK > > Encryption: AES or TKIP > > ''' > > > >s = s.replace("=",":") > ># s = s.strip() > >print s > > > > d = {} > > for i in s: > > key, val = i.split(":") > > d[key] = val.strip() > > > > print d > > print d["ip address"] > > > > > > Getting below error : > > key, val = i.split(":") > > ValueError: need more than 1 value to unpack > > -- > > https://mail.python.org/mailman/listinfo/python-list > > If you iterate over a string, you are iterating over individual > characters. Instead, you need to split it into lines, first stripping > whitespace (starts and ends with an empty line). > > s = s.strip().replace("=",":") > print s > > d = {} > for i in s.split('\n'): > try: > key, val = i.split(":") > d[key.strip()] = val.strip() > except ValueError: > print "no key:value pair found in", i > > > (PS. please switch to Python 3) > > -- > Chris Warrick <https://chriswarrick.com/> > PGP: 5EAAEA16 > -- https://mail.python.org/mailman/listinfo/python-list
Getting "ValueError: need more than 1 value to unpack" while trying to read a value from dictionary in python
Below is my code. Here I want to read the "ip address" from s s= ''' Power On Enabled = On State: connected Radio Module: Unknown noise: -097 signalStrength: -046 ip address: 192.168.75.147 subnet mask: 255.255.255.0 IPv4 address configured by DHCP Mac Addr: ac:e2:d3:32:00:5a Mode: infrastrastructure ssid: Cloudlab Channel: 1 Regulatory: World Safe Authencation: WPA2/PSK Encryption: AES or TKIP ''' s = s.replace("=",":") # s = s.strip() print s d = {} for i in s: key, val = i.split(":") d[key] = val.strip() print d print d["ip address"] Getting below error : key, val = i.split(":") ValueError: need more than 1 value to unpack -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] How to set/update value in a xml file using requests in python
Thanks Dan for your response. I have updated the data to be sent in xml format and now I am able to update the required fields using put request. data= ''' web-proxy.xx.com 8080 on ''' On Thu, Feb 8, 2018 at 10:15 PM, Dan Stromberg <drsali...@gmail.com> wrote: > This is more relevant to python-list than python-dev. I've added > python-list to the To header. > > Gmail doesn't appear to allow setting a reply-to for a single message, > so I've not set that; please, when replying, drop python-dev from the > to: header. > > You'll likely want to set up some kind of REST endpoint to allow > updating your xml file. Imagine if anyone could change anyone else's > xml files - it'd be pretty chaotic. > > Perhaps flask would be appropriate? > http://flask.pocoo.org/docs/0.12/quickstart/ > > You likely will want a PUT or a POST HTTP verb: > https://stackoverflow.com/questions/107390/whats-the- > difference-between-a-post-and-a-put-http-request > > HTH. > > On Thu, Feb 8, 2018 at 12:38 AM, Sum J <sjsum...@gmail.com> wrote: > > My xml file is located in local network: > > > > http://192.168.43.109/DevMgmt/NetAppsDyn.xml > > > > Below is a part content of above xml I want to update : > > > > > > > > > > > > > > off > > > > > > > > > > I want to set the value for 'ResourceUI' and 'Port' field in above xml. > > > > I have used below code : > > > > import requests > > data = { > > 'ResourceURI':'web-proxy.xxx.yy.com', > > 'Port':8080 > > } > > > > URL = 'http://192.168.75.165/DevMgmt/NetAppsDyn.xml' > > > > # content type > > head = {'Content-type': 'text/xml'} > > # sending get request > > gr= requests.get(url=URL) > > print gr > > > > # sending put request > > r = requests.put(url=URL, data=data,headers=head) > > print r.status_code > > # extracting response text > > output_xml = r.text > > print("The op xml is:%s" % output_xml) > > > > Issue : The fields are not getting updated in xml using put request. I am > > able to see the response for get (request) , but for put request it is > > throwing errror code : 301 , resource has been moved permanently. > > > > > > > > ___ > > Python-Dev mailing list > > python-...@python.org > > https://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe: > > https://mail.python.org/mailman/options/python-dev/drsalists%40gmail.com > > > -- https://mail.python.org/mailman/listinfo/python-list
How to set/update value in a xml file using requests in python
My xml file is located in local network : http://192.168.43.109/DevMgmt/NetAppsDyn.xml Below is a part content of above xml I want to update : off I want to set value for 'ResourceUI' and 'Port' field in above xml. I have used below code : data = { 'ResourceURI':'web-proxy.xxx.yy.com', 'Port':8080 } URL = 'http://192.168.75.165/DevMgmt/NetAppsDyn.xml' # content type head = {'Content-type': 'text/xml'} # sending get request gr= requests.get(url=URL) print gr # sending put request r = requests.put(url=URL, data=data,headers=head) print r.status_code # extracting response text output_xml = r.text print("The op xml is:%s" % output_xml) Issue : The fields are not getting updated in xml using put request. I am able to see the response for get (request) , but for put request it is throwing errror code : 301 , resource has been moved permanently. -- https://mail.python.org/mailman/listinfo/python-list