Newrelic plugin nginx-nr-agent not working - nginx

I am using Newrelic's nginx-nr-agent but suddenly it crashed giving out the following error and not starting back.
2016-04-12 07:51:07,021 nginx-nr-agent [ERROR]: EXCEPTION: Traceback (most recent call last):
File "/usr/bin/nginx-nr-agent.py", line 431, in newrelic_push
u = urlopen(r, data=json.dumps(payload))
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 401, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 419, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1219, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
r = h.getresponse(buffering=True)
File "/usr/lib/python2.7/httplib.py", line 1034, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 407, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
line = self.fp.readline()
File "/usr/lib/python2.7/socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
File "/usr/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
File "/usr/lib/pymodules/python2.7/daemon/daemon.py", line 399, in terminate
raise exception
SystemExit: Terminating on signal 15
Any help please?

I got two solution for this from here, one is to remove the pid file /var/run/nginx-nr-agent/nginx-nr-agent.pid and than start/restart it. And second solution is to restart the server.

This plugin is published and supported by Nginx, Inc. If the previous suggestions did not help, contact
newrelic-support#nginx.com.

Related

ngrok account token connection is not working

in terminal:
ngrok config add-authtoken -----personal_TOKEN-----
when ı tryed for this ı'm getting this error
ı downloaded the pyngrok but still ı have this issue.
Thanks for any help !
Traceback (most recent call last):
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/installer.py", line 94, in install_ngrok
download_path = _download_file(url, **kwargs)
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/installer.py", line 257, in _download_file
raise e
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/installer.py", line 235, in _download_file
buffer = response.read(chunk_size)
File "/usr/lib/python3.8/http/client.py", line 459, in read
n = self.readinto(b)
File "/usr/lib/python3.8/http/client.py", line 503, in readinto
n = self.fp.readinto(b)
File "/usr/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/selman/PycharmProjects/tringle-case/venv/bin/ngrok", line 8, in <module>
sys.exit(main())
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/ngrok.py", line 501, in main
run(sys.argv[1:])
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/ngrok.py", line 487, in run
install_ngrok(pyngrok_config)
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/ngrok.py", line 98, in install_ngrok
installer.install_ngrok(pyngrok_config.ngrok_path)
File "/home/selman/PycharmProjects/tringle-case/venv/lib/python3.8/site-packages/pyngrok/installer.py", line 98, in install_ngrok
raise PyngrokNgrokInstallError("An error occurred while downloading ngrok from {}: {}".format(url, e))
pyngrok.exception.PyngrokNgrokInstallError: An error occurred while downloading ngrok from https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip: The read operation timed out
The documentation is faulty. Try this:
ngrok.exe authtoken xxxxxxxxxxxxxxxxxxxxxxxxx
Replace xxxxxxx with your token.

Unable to load function install_tensorflow() in r

Hi I have encountered such problem when loading the function install_tensorflow() in r.
I don't know what to do with this error. Any help will be greatly appreciated!
Below is the error message
ERROR: Exception:
Traceback (most recent call last):
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 171, in _merge_into_criterion
crit = self.state.criteria[name]
KeyError: 'tensorflow'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher
yield
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/http/client.py", line 461, in read
n = self.readinto(b)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/http/client.py", line 505, in readinto
n = self.fp.readinto(b)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 189, in _main
status = self.run(options, args)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 178, in wrapper
return func(self, options, args)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 317, in run
reqs, check_supported_wheels=not options.target_dir
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 122, in resolve
requirements, max_rounds=try_to_avoid_resolution_too_deep,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 453, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 318, in resolve
name, crit = self._merge_into_criterion(r, parent=None)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _merge_into_criterion
crit = Criterion.from_requirement(self._p, requirement, parent)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 82, in from_requirement
if not cands:
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/resolvelib/structs.py", line 124, in bool
return bool(self._sequence)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in bool
return any(self)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 38, in _iter_built
candidate = func()
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 169, in _make_candidate_from_link
name=name, version=version,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 306, in init
version=version,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 144, in init
self.dist = self._prepare()
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 226, in _prepare
dist = self._prepare_distribution()
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 312, in _prepare_distribution
self._ireq, parallel_builds=True,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 457, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 482, in _prepare_linked_requirement
self.download_dir, hashes,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 234, in unpack_url
hashes=hashes,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 108, in get_http_url
from_path, content_type = download(link, temp_dir.path)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/network/download.py", line 163, in call
for chunk in chunks:
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/cli/progress_bars.py", line 159, in iter
for x in it:
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_internal/network/utils.py", line 88, in response_chunks
decode_content=False,
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/contextlib.py", line 130, in exit
self.gen.throw(type, value, traceback)
File "/Users/alexsong/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
Error: Error installing package(s): 'tensorflow==2.4'

python integration with azure gremlin not working

I am trying to mimic as mentioned in GIT.
I almost commented everything, and just trying to run simply
g.V().count()
my connection details are correct, and matched to documentation...
I am getting following error.
Traceback (most recent call last):
File "c:\Users\PrasaRak\OneDrive\gremlin_azure_function\connect.py", line 193, in <module>
count_vertices(client)
File "c:\Users\PrasaRak\OneDrive\gremlin_azure_function\connect.py", line 116, in count_vertices
callback = client.submit(_gremlin_count_vertices)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\gremlin_python\driver\client.py", line 127, in submit
return self.submitAsync(message, bindings=bindings, request_options=request_options).result()
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\gremlin_python\driver\client.py", line 148, in submitAsync
return conn.write(message)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\gremlin_python\driver\connection.py", line 55, in write
self.connect()
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\gremlin_python\driver\connection.py", line 45, in connect
self._transport.connect(self._url, self._headers)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\gremlin_python\driver\tornado\transport.py", line 40, in connect
self._ws = self._loop.run_sync(
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\ioloop.py", line 576, in run_sync
return future_cell[0].result()
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\simple_httpclient.py", line 269, in run
stream = yield self.tcp_client.connect(
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\gen.py", line 1133, in run
value = future.result()
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\gen.py", line 1147, in run
yielded = self.gen.send(value)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\tcpclient.py", line 232, in connect
af, addr, stream = yield connector.start(connect_timeout=timeout)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\tcpclient.py", line 87, in start
self.try_connect(iter(self.primary_addrs))
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\tcpclient.py", line 104, in try_connect
stream, future = self.connect(af, addr)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\tcpclient.py", line 276, in _create_stream
return stream, stream.connect(addr)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\iostream.py", line 1325, in connect
self._add_io_state(self.io_loop.WRITE)
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\iostream.py", line 1157, in _add_io_state
self.io_loop.add_handler(
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\site-packages\tornado\platform\asyncio.py", line 83, in add_handler
self.asyncio_loop.add_writer(
File "C:\Users\PrasaRak\Miniconda3\envs\learn-gremlin\lib\asyncio\events.py", line 507, in add_writer
raise NotImplementedError
NotImplementedError
I think i got the answer.
issue was with python 3.8 & Tornado compatibility, when it comes to asyncio.
more info is at this link
fix was to add following line in tornado/platform/asyncio.py
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # python-3.8.0a4

Connect to web server using python3 socket

I'm running Python3 running Django on localhost and listening to http://127.0.0.1:8000/
and I want to test it by different ways like request and socket
import requests
res = requests.request("GET", "http://127.0.0.1:8000/")
txt = res.content
print(res)
res.close()
# <Response [200]>
It runs well, and
on my running Django console, it shows [07/Jul/2018 16:04:26] "GET / HTTP/1.1" 200 6744
Now instead requests to socket
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 8000))
msg = b'GET / HTTP/1.1'
s.send(msg)
print(s)
s.close()
# <socket.socket fd=1324, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 55312), raddr=('127.0.0.1', 8000)>
No error shows in my program
But I got the following exception on my running Django console
Invalid HTTP_HOST header: 'tony.jhou-1.xxservice.com:8000'. You may need to add 'tony.jhou-1.xxservice.com:8000' to ALLOWED_HOSTS.
[07/Jul/2018 16:08:10] "GET / HTTP/1.1" 400 63266
Traceback (most recent call last):
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\socketserver.py", line 775, in write
self._sock.sendall(b)
File "D:\emc\ve\lib\site-packages\gevent\_socket3.py", line 459, in sendall
return _socketcommon._sendall(self, data_memory, flags)
File "D:\emc\ve\lib\site-packages\gevent\_socketcommon.py", line 358, in _sendall
timeleft = __send_chunk(socket, chunk, flags, timeleft, end)
File "D:\emc\ve\lib\site-packages\gevent\_socketcommon.py", line 287, in __send_chunk
data_sent += socket.send(chunk, flags)
File "D:\emc\ve\lib\site-packages\gevent\_socket3.py", line 440, in send
return _socket.socket.send(self._sock, data, flags)
ConnectionAbortedError: [WinError 10053] 連線已被您主機上的軟體中止。
[07/Jul/2018 16:08:10] "GET / HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54587)
Traceback (most recent call last):
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\socketserver.py", line 775, in write
self._sock.sendall(b)
File "D:\emc\ve\lib\site-packages\gevent\_socket3.py", line 459, in sendall
return _socketcommon._sendall(self, data_memory, flags)
File "D:\emc\ve\lib\site-packages\gevent\_socketcommon.py", line 358, in _sendall
timeleft = __send_chunk(socket, chunk, flags, timeleft, end)
File "D:\emc\ve\lib\site-packages\gevent\_socketcommon.py", line 287, in __send_chunk
data_sent += socket.send(chunk, flags)
File "D:\emc\ve\lib\site-packages\gevent\_socket3.py", line 440, in send
return _socket.socket.send(self._sock, data, flags)
ConnectionAbortedError: [WinError 10053] 連線已被您主機上的軟體中止。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "D:\emc\ve\lib\site-packages\django\core\servers\basehttp.py", line 88, in handle_error
super(ServerHandler, self).handle_error()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\socketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\socketserver.py", line 696, in __init__
self.handle()
File "D:\emc\ve\lib\site-packages\django\core\servers\basehttp.py", line 155, in handle
handler.run(self.server.get_app())
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\tony.jhou\AppData\Local\Continuum\Anaconda3\lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
I'm new to socket programming and just start learning networking, I think maybe I should send more request head. Please tell me how to do that, thanks.
Yes, you need to send more data. A minimal HTTP 1.1 request requires a second line that contains a Host header specifying the name or address of the host that should handle the request, and the request header lines must be followed by an empty line to tell the server that the header has been completely received.
In HTTP the end of a line is indicated by a pair of characters, a carriage return and a line feed. In Python strings \r represents a carriage return and \n represents a line feed. (The line feed character is sometimes called a newline character, hence the \n code.) This means that you have to write \r\n to mark the end of each line in the request.
So, what you need is:
msg = b'GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n'
The final \r\n produces the empty line that indicates the end of the headers.
After you make that change it's likely that your server will report a different error, because your client program closes its socket immediately. That breaks the connection between the client and the server. When the server tries to send its response, it will find that the connection has been broken and it will probably complain about that. To avoid that, change your client to use s.recv to wait for and read the response from the server after it does s.send(). Something like:
while True:
resp = s.recv(8000)
if resp:
print resp
else:
break

How can I fix biopython urllib.error.HTTPError 502?

Hi I am using biopython to pull files from NCBI using Entrez. The program works on small files but on larger files I get an error. I would really appreciate some insight or help figuring out what went wrong.
Here is the program:
from Bio import Entrez
Entrez.email = "jbro262#lsu.edu"
search_handle = Entrez.esearch(db="nucleotide",term="Saimiri",usehistory="n")
search_results = Entrez.read(search_handle)
search_handle.close()
gi_list = search_results["IdList"]
count = int(search_results["Count"])
a = open("Numfile.txt", "a+")
a.write("The number of Saimiri files are :")
a.write(str(count))
a.write("\n")
a.close()
webenv = search_results["WebEnv"]
query_key = search_results["QueryKey"]
batch_size = 25
out_handle = open("SaimiriDNA.fasta", "w")
for start in range(0,count,batch_size):
end = min(count, start+batch_size)
print("Going to download record %i to %i" % (start+1, end))
fetch_handle = Entrez.efetch(db="nucleotide", rettype="fasta", retmode="text", retstart=start, retmax=batch_size, webenv=webenv, query_key=query_key)
data=fetch_handle.read()
fetch_handle.close()
out_handle.write(data)
out_handle.close()
Here are the errors:
Traceback (most recent call last):
File "Entrezfiles_Saimiri.py", line 53, in <module>
fetch_handle = Entrez.efetch(db="nucleotide", rettype="fasta", retmode="text", retstart=start, retmax=batch_size, webenv=webenv, query_key=query_key)
File "/usr/local/lib/python3.4/
dist-packages/Bio/Entrez/__init__.py", line 149, in efetch
return _open(cgi, variables, post)
File "/usr/local/lib/python3.4/dist-packages/Bio/Entrez/__init__.py", line 464, in _open
raise exception
File "/usr/local/lib/python3.4/dist-packages/Bio/Entrez/__init__.py", line 462, in _open
handle = _urlopen(cgi)
File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.4/urllib/request.py", line 461, in open
response = meth(req, response)
File "/usr/lib/python3.4/urllib/request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.4/urllib/request.py", line 499, in error
return self._call_chain(*args)
File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/lib/python3.4/urllib/request.py", line 579, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 502: Bad Gateway
Does this mean something is going wrong with my server while the files are downloading?

Resources