WARNING: NEOS is temporarily unavailable. - Pyomo - pyomo

I'm trying to learn how to send an optimization problem to NEOS Server to solve it with BARON, but I'm receiving an error which says NEOS is currently unavailable even though I've been trying it for some time. I've seen that there exists another question with the same error code, but it has not been resolved and people suspect it to be caused by using a proxy (Which I do not) therefore I opened another question.
from pyomo.environ import *
model = ConcreteModel()
model.x = Var(initialize=1.5)
model.y = Var(initialize=1.5)
def rosenbrock(model):
return (1.0-model.x)**2 + 100.0*(model.y - model.x**2)**2
model.obj = Objective(rule=rosenbrock, sense=minimize)
solver_manager = SolverManagerFactory('neos')
results = solver_manager.solve(model, opt='baron')
results.write()
And the output is:
WARNING: NEOS is temporarily unavailable.
Traceback (most recent call last):
File "/Users/dorukeski/untitled/sa.py", line 15, in <module>
results = solver_manager.solve(model, opt='baron')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/opt/parallel/async_solver.py", line 28, in solve
return self.execute(*args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/opt/parallel/manager.py", line 119, in execute
ah = self.queue(*args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/opt/parallel/manager.py", line 134, in queue
return self._perform_queue(ah, *args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/neos/plugins/kestrel_plugin.py", line 128, in _perform_queue
raise ActionManagerError(
pyomo.opt.parallel.manager.ActionManagerError: Solver 'baron' is not recognized by NEOS.
Solver names recognized:
[]

Though this post is an old post.
I see someone suggested the fix in this link, https://github.com/Pyomo/pyomo/issues/2162
solution 1:
pip install --upgrade certifi
solution 2 if solution 1 not working:
1 - Open Internet Explorer as an Administrator (i.e., right-click on Internet Explorer and choose "Run as administrator")
2 - Navigate to https://neos-server.org
3 - Click on the lock icon
Click to view the image
4 - Click "View Certificate"
5 - Click "Install certificate..."
6 - Choose user or local machine, whatever is appropriate
7 - Select "Place all certificates in the following store" and choose "Trusted Root
8 - Certification Authorities"

Related

pyomo mindtpy example program when run becomes unfeasible for binary variable

So I installed pyomo, glpk, and ipopt with anaconda,
When I run the example code here: https://pyomo.readthedocs.io/en/stable/contributed_packages/mindtpy.html
from pyomo.environ import *
model = ConcreteModel()
model.x = Var(bounds=(1.0,10.0),initialize=5.0)
model.y = Var(within=Binary)
model.c1 = Constraint(expr=(model.x-3.0)**2 <= 50.0*(1-model.y))
model.c2 = Constraint(expr=model.x*log(model.x)+5.0 <= 50.0*(model.y))
model.objective = Objective(expr=model.x, sense=minimize)
SolverFactory('mindtpy').solve(model, mip_solver='glpk', nlp_solver='ipopt',tee=True)
model.objective.display()
model.display()
model.pprint()
I get the output that the binary variable has apparently become infeasible:
python minlpex.py
INFO: ---Starting MindtPy---
INFO: Original model has 2 constraints (2 nonlinear) and 0 disjunctions, with
2 variables, of which 1 are binary, 0 are integer, and 1 are continuous.
INFO: NLP 1: Solve relaxed integrality
INFO: NLP 1: OBJ: 1.0 LB: 1.0 UB: inf
INFO: ---MindtPy Master Iteration 0---
INFO: MIP 1: Solve master problem.
WARNING: Empty constraint block written in LP format - solver may error
Traceback (most recent call last):
File "minlpex.py", line 13, in <module>
op.SolverFactory('mindtpy').solve(model, mip_solver='glpk', nlp_solver='ipopt',tee=True)
File "/anaconda3/envs/py36/lib/python3.6/site-packages/pyomo/contrib/mindtpy/MindtPy.py", line 370, in solve
MindtPy_iteration_loop(solve_data, config)
File "/anaconda3/envs/py36/lib/python3.6/site-packages/pyomo/contrib/mindtpy/iterate.py", line 30, in MindtPy_iteration_loop
handle_master_mip_optimal(master_mip, solve_data, config)
File "/anaconda3/envs/py36/lib/python3.6/site-packages/pyomo/contrib/mindtpy/mip_solve.py", line 62, in handle_master_mip_optimal
config)
File "/anaconda3/envs/py36/lib/python3.6/site-packages/pyomo/contrib/gdpopt/util.py", line 199, in copy_var_list_values
v_to.set_value(value(v_from, exception=False))
File "/anaconda3/envs/py36/lib/python3.6/site-packages/pyomo/core/base/var.py", line 173, in set_value
if valid or self._valid_value(val):
File "/anaconda3/envs/py36/lib/python3.6/site-packages/pyomo/core/base/var.py", line 185, in _valid_value
"domain %s" % (val, type(val), self.domain))
ValueError: Numeric value `0.22709088987977885` (<class 'float'>) is not in domain Binary
So I was a little confused, since this was a code provided, I would not expect it to error like this. So I feel like I'm messing something up or I am missing some required library?
Thanks a lot.
Looks like something must be wrong with the conda pyomo install or ipopt install.
When I reinstalled using pip for ipopt and compiling pyomo from github source everything works fine.

when webdriver can’t find elem,Failed to establish a new connection [duplicate]

I have one question:I want to test "select" and "input".can I write it like the code below:
original code:
12 class Sinaselecttest(unittest.TestCase):
13
14 def setUp(self):
15 binary = FirefoxBinary('/usr/local/firefox/firefox')
16 self.driver = webdriver.Firefox(firefox_binary=binary)
17
18 def test_select_in_sina(self):
19 driver = self.driver
20 driver.get("https://www.sina.com.cn/")
21 try:
22 WebDriverWait(driver,30).until(
23 ec.visibility_of_element_located((By.XPATH,"/html/body/div[9]/div/div[1]/form/div[3]/input"))
24 )
25 finally:
26 driver.quit()
# #测试select功能
27 select=Select(driver.find_element_by_xpath("//*[#id='slt_01']")).select_by_value("微博")
28 element=driver.find_element_by_xpath("/html/body/div[9]/div/div[1]/form/div[3]/input")
29 element.send_keys("杨幂")
30 driver.find_element_by_xpath("/html/body/div[9]/div/div[1]/form/input").click()
31 driver.implicitly_wait(5)
32 def tearDown(self):
33 self.driver.close()
I want to test Selenium "select" function.so I choose sina website to select one option and input text in textarea.then search it .but when I run this test,it has error:
Traceback (most recent call last):
File "test_sina_select.py", line 32, in tearDown
self.driver.close()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 688, in close
self.execute(Command.CLOSE)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 376, in execute
return self._request(command_info[0], url, body=data)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 399, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 68, in request
**urlopen_kw)
File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 81, in request_encode_url
return self.urlopen(method, url, **urlopen_kw)
File "/usr/lib/python2.7/site-packages/urllib3/poolmanager.py", line 247, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 597, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python2.7/site-packages/urllib3/util/retry.py", line 271, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=51379): Max retries exceeded with url: /session/2e64d2a1-3c7f-4221-96fe-9d0b1c102195/window (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))
----------------------------------------------------------------------
Ran 1 test in 72.106s
who can tell me why?thanks
This error message...
MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=51379): Max retries exceeded with url: /session/2e64d2a1-3c7f-4221-96fe-9d0b1c102195/window (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))
...implies that the call to self.driver.close() method failed raising MaxRetryError.
A couple of things:
First and foremost as per the discussion max-retries-exceeded exceptions are confusing the traceback is somewhat misleading. Requests wraps the exception for the users convenience. The original exception is part of the message displayed.
Requests never retries (it sets the retries=0 for urllib3's HTTPConnectionPool), so the error would have been much more canonical without the MaxRetryError and HTTPConnectionPool keywords. So an ideal Traceback would have been:
ConnectionError(<class 'socket.error'>: [Errno 1111] Connection refused)
But again #sigmavirus24 in his comment mentioned ...wrapping these exceptions make for a great API but a poor debugging experience...
Moving forward the plan was to traverse as far downwards as possible to the lowest level exception and use that instead.
Finally this issue was fixed by rewording some exceptions which has nothing to do with the actual connection refused error.
Solution
Even before self.driver.close() within tearDown(self) is invoked, the try{} block within test_select_in_sina(self) includes finally{} where you have invoked driver.quit()which is used to call the /shutdown endpoint and subsequently the web driver & the client instances are destroyed completely closing all the pages/tabs/windows. Hence no more connection exists.
You can find a couple of relevant detailed discussion in:
PhantomJS web driver stays in memory
Selenium : How to stop geckodriver process impacting PC memory, without calling
driver.quit()?
In such a situation when you invoke self.driver.close() the python client is unable to locate any active connection to initiate a clousure. Hence you see the error.
So a simple solution would be to remove the line driver.quit() i.e. remove the finally block.
tl; dr
As per the Release Notes of Selenium 3.14.1:
* Fix ability to set timeout for urllib3 (#6286)
The Merge is: repair urllib3 can't set timeout!
Conclusion
Once you upgrade to Selenium 3.14.1 you will be able to set the timeout and see canonical Tracebacks and would be able to take required action.
References
A couple of relevent references:
Adding max_retries as an argument
Removed the bundled charade and urllib3.
Third party libraries committed verbatim
Just had the same problem. The solution was to change the owner of the folder with a script recursively. In my case the folder had root:root owner:group and I needed to change it to ubuntu:ubuntu.
Solution: sudo chown -R ubuntu:ubuntu /path-to-your-folder
Use Try and catch block to find exceptions
try:
r = requests.get(url)
except requests.exceptions.Timeout:
#Message
except requests.exceptions.TooManyRedirects:
#Message
except requests.exceptions.RequestException as e:
#Message
raise SystemExit(e)

Unsolved Reference IP() and TCP() When Using Scapy

I copied the codes from the example to learn scapy. But realized the IDE showed the error with unsolved reference for IP() & TCP(). Anyone know how to fix this?
Here are the codes:
#! /usr/bin/env python
from scapy.all import *
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
dst_ip = "10.0.0.1"
src_port = RandShort()
dst_port=80
tcp_connect_scan_resp = sr1(IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags="S"), timeout=10)
if(str(type(tcp_connect_scan_resp))==""):
print("Closed")
elif(tcp_connect_scan_resp.haslayer(TCP)):
if(tcp_connect_scan_resp.getlayer(TCP).flags == 0x12):
send_rst =sr(IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags="AR"),timeout=10)
print("Open")
elif (tcp_connect_scan_resp.getlayer(TCP).flags ==0x14):
print("Closed")
I'm using Pycharm IDE. Python2.7 and scapy 2.4.0. I searched on stackoverflow and found someone asked the same question before but no answer.....
Here is the error after I tried to run the codes:
/Users/chenneyhuang/PycharmProjects/Scanner/venv/bin/python /Users/chenneyhuang/PycharmProjects/Scanner/TCP.py
Traceback (most recent call last):
File "/Users/chenneyhuang/PycharmProjects/Scanner/TCP.py", line 12, in <module>
tcp_connect_scan_resp = sr1(IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags="S"), timeout=10)
File "/Users/chenneyhuang/PycharmProjects/Scanner/venv/lib/python2.7/site-packages/scapy/sendrecv.py", line 393, in sr1
s=conf.L3socket(promisc=promisc, filter=filter, nofilter=nofilter, iface=iface)
File "/Users/chenneyhuang/PycharmProjects/Scanner/venv/lib/python2.7/site-packages/scapy/arch/bpf/supersocket.py", line 58, in __init__
(self.ins, self.dev_bpf) = get_dev_bpf()
File "/Users/chenneyhuang/PycharmProjects/Scanner/venv/lib/python2.7/site-packages/scapy/arch/bpf/core.py", line 98, in get_dev_bpf
raise Scapy_Exception("No /dev/bpf handle is available !")
scapy.error.Scapy_Exception: No /dev/bpf handle is available !
Process finished with exit code 1
I answered the same Unsolved Reference issue last week here:
vscode import error: from scapy.all import IP
In short, don't worry about that error, it's a limitation of Pylint (or similar). I propose a workaround in the other question, if you'd like to remove the error/warning.
For the No /dev/bpf handle is available error, have you tried running the script as root? I see that suggested as a solution over on this GitHub issue: https://github.com/secdev/scapy/issues/1343

'WebSocketProtocol' object has no attribute 'application_queue' error Django Channels

In my Django project I want to create a chat app using channels.But when I followed this tutorial:
https://channels.readthedocs.io/en/stable/tutorial/part_2.html , I had a problem that websocket auto disconnect after connect :
Exception in callback AsyncioSelectorReactor.callLater.<locals>.run()
at
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\asyncioreact
or.py:287 handle: <TimerHandle when=19405.993
AsyncioSelectorReactor.callLater.<locals>.run() at
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\interne
t\asyncioreactor.py:287> Traceback (most recent call last): File
"C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\events.py",
line 145, in _run
self._callback(*self._args) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\asyncioreactor.py",
line 290, in run
f(*args, **kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\tcp.py",
line 289, in connectionLost
protocol.connectionLost(reason) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\twisted\websocket.py",
line 128, in connectionLost
self._connectionLost(reason) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\websocket\protocol.py",
line 2467, in _connectionLost
WebSocketProtocol._connectionLost(self, reason) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\websocket\protocol.py",
line 1096, in _connectionLost
self._onClose(self.wasClean, WebSocketProtocol.CLOSE_STATUS_CODE_ABNORMAL_CLOSE, "connection was
closed uncleanly (%s)" % self.wasNotCleanReason) File
"C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\twisted\websocket.py",
line 171, in _onClose
self.onClose(wasClean, code, reason) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\daphne\ws_protocol.py",
line 146, in onClose
self.application_queue.put_nowait({ AttributeError: 'WebSocketProtocol' object has no attribute 'application_queue'
Above this error should be a list of paths and at the top of that paths are the real error. In my case it was the routing url.
migration solve it for me
python manage.py migrate
Just to clarify this error for everyone who faces it while following the channels tutorial for me the error was in my path
2018-05-17 15:55:36,382 - ERROR - ws_protocol - [Failure instance:
Traceback: : No route found for path
'ws/chat/me/'.
You can find it on top of the stacktrace
My defined invalid URL pattern "buzz" because I like to change things up. Essentially it works the same way as django url patterns so just need to make sure that your routing structure matches what you specify.
websocket_urlpatterns = [
url(r'^ws/buzz/(?P<room_name>[^/]+)/$', consumers.ChatConsumer),
]
In my case the route path did not match my websocket patterns
I had to update the route path to be correct -> by changing my websocket_urlpatterns back to chat
websocket_urlpatterns = [
url(r'^ws/chat/(?P<room_name>[^/]+)/$', consumers.ChatConsumer),
]
So the system could resolve my issue. Hopefully it helps people who run into this in the future. Good luck. P.T.

Running stem with tor gives "Process terminated: Timed out"

While trying to run Stem's To Russia With Love example, I am getting the following error:
~$ python practice.py
Starting Tor:
Traceback (most recent call last):
File "practice.py", line 49, in <module>
init_msg_handler = print_bootstrap_lines,
File "/usr/local/lib/python2.7/dist-packages/stem/process.py", line 266, in launch_tor_with_config
return launch_tor(tor_cmd, args, torrc_path, completion_percent, init_msg_handler, timeout, take_ownership)
File "/usr/local/lib/python2.7/dist-packages/stem/process.py", line 143, in launch_tor
raise OSError('Process terminated: %s' % last_problem)
OSError: Process terminated: Timed out
I was initially getting the path error that was solved over here. I tried restarting the Ubuntu instance (I am running Ubuntu 14.04 in VirtualBox) just in case if any other running tor was conflicting but its giving the same error. Could anyone please help?
EDIT: My torrc file also seems to be empty right now if this is in any way connected.
It might be failing because you are missing the GeoIP database which is required to use an exit node from a specific country.
Try removing the 'ExitNodes': '{ru}', line from the python script, or since you're on Ubuntu, try sudo apt-get install tor-geoipdb and see if that helps get the connection up and running.
Since it takes time to build the circuits, you can try increasing the timeout a bit as well (though this probably isn't why its failing).
tor_process = stem.process.launch_tor_with_config(
#tor_cmd = '/usr/bin/tor',
timeout = 300,
config = {
'SocksPort': str(SOCKS_PORT),
# 'ExitNodes': '{ru}',
'DataDir': '/tmp/tor',
'Log': [
'NOTICE file /tmp/tor.notice.log',
'ERR file /tmp/tor.log',
],
},
init_msg_handler = print_bootstrap_lines,
)