Problem:
I'm trying to debug some of my code that uses Softlayer Object Storage however I kept getting some errors from SL itself. Since I was getting the error from SL I went ahead and tried writing some code that reproduces the error. Which can be seen below followed by the stack trace I get.
Question:
Does anyone know why I'm getting the below error besides the possible security prevention from spamming sl so many times?
Source Code:
#!/usr/local/bin/python2.7
import argparse
import object_storage
def main():
parser = argparse.ArgumentParser(description='Spam multiple sl storage containers.')
parser.add_argument("--username", type=str, required=True, help="softlayer username")
parser.add_argument("--apikey", type=str, required=True, help="softlayer api key")
parser.add_argument("--datacenter", type=str, required=True, help="softlayer datacenter")
parser.add_argument("--count", type=int, required=True, help="Amount of times to iterate")
args = parser.parse_args()
username = args.username
api_key = args.apikey
datacenter = args.datacenter
count = args.count
for i in range(0, count):
print "Trying to create sl_storage.containers() #{0}".format(i)
sl_storage = object_storage.get_client(username, api_key, datacenter=datacenter)
containers = sl_storage.containers()
del containers
del sl_storage
if __name__ == "__main__":
main()
Stack Trace:
Traceback (most recent call last):
File "/root/sl_test.py", line 32, in <module>
main()
File "/root/sl_test.py", line 27, in main
containers = sl_storage.containers()
File "/usr/local/lib/python2.7/site-packages/object_storage/client.py", line 293, in containers
formatter=_formatter)
File "/usr/local/lib/python2.7/site-packages/object_storage/client.py", line 354, in make_request
result = self.conn.make_request(method, url, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/object_storage/transport/httplib2conn.py", line 55, in make_request
response = _make_request(headers)
File "/usr/local/lib/python2.7/site-packages/object_storage/transport/httplib2conn.py", line 48, in _make_request
body=data)
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1659, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1399, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1325, in _conn_request
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at dal05.objectstorage.softlayer.net
Opened up an issues against softlayer-object_storage python package here https://github.com/softlayer/softlayer-object-storage-python/issues/50
First: I think you should have opened the issue here:
https://github.com/softlayer/softlayer-object-storage-python
second: I do not think this is an issue for me this is working fine, the error probably is due to you do not have any storage in dal05, you can verify that in the control portal by going https://control.softlayer.com/storage/objectstorage and make sure that there are containers in the dal05.
third: the client that you are using only works for swift storages, it does not work for S3 containers
The storage in this issue is Swift-based not S3.
Related
I've deployed a sagemaker endpoint using the following code:
from sagemaker.pytorch import PyTorchModel
from sagemaker import get_execution_role, Session
sess = Session()
role = get_execution_role()
model = PyTorchModel(model_data=my_trained_model_location,
role=role,
sagemaker_session=sess,
framework_version='1.5.0',
entry_point='inference.py',
source_dir='.')
predictor = model.deploy(initial_instance_count=1,
instance_type='ml.m4.xlarge',
endpoint_name='my_endpoint')
If I run:
import numpy as np
pseudo_data = [np.random.randn(1, 300), np.random.randn(6, 300), np.random.randn(3, 300), np.random.randn(7, 300), np.random.randn(5, 300)] # input data is a list of 2D numpy arrays with variable first dimension and fixed second dimension
result = predictor.predict(pseudo_data)
I can generate the result with no errors. However, if I want to invoke the endpoint and make prediction by running:
from sagemaker.predictor import RealTimePredictor
predictor = RealTimePredictor(endpoint='my_endpoint')
result = predictor.predict(pseudo_data)
I'd get an error:
Traceback (most recent call last):
File "default_local.py", line 77, in <module>
score = predictor.predict(input_data)
File "/home/biggytruck/.local/lib/python3.6/site-packages/sagemaker/predictor.py", line 113, in predict
response = self.sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/client.py", line 608, in _make_api_call
api_params, operation_model, context=request_context)
File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/client.py", line 656, in _convert_to_request_dict
api_params, operation_model)
File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/validate.py", line 297, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Body
From my understanding, the error occurs because I didn't pass in inference.py as the entry point file, which is required to handle the input since it's not in a standard format supported by Sagemaker. However, sagemaker.predictor.RealTimePredictor doesn't allow me to define the entry point file. How can I solve this?
The error you're seeing is raised from the clientside SageMaker Python SDK library, not the remote endpoint that you have published.
Here is the documentation for the data argument (in your case, this is pseudo_data)
data (object) – Input data for which you want the model to provide inference. If a serializer was specified when creating the RealTimePredictor, the result of the serializer is sent as input data. Otherwise the data must be sequence of bytes, and the predict method then sends the bytes in the request body as is.
Source: https://sagemaker.readthedocs.io/en/stable/api/inference/predictors.html#sagemaker.predictor.RealTimePredictor.predict
My guess is that pseudo_data is not the type that the SageMaker Python SDK is expecting, which is a sequence of bytes.
I am playing around with Flask. I have created an API using Flask-Restful and Flask-JWT. When Debug=True in Flask, and I do not send the Authorization Header, I get the response as However, when the debug=False, the response returned is Internal Server Error with this stack trace,
[2017-01-19 19:43:10,753] ERROR in app: Exception on /api_0_1/deals [GET]
Traceback (most recent call last):
File "C:\Users\ARFATS~1\Desktop\Dealflow\venv\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\ARFATS~1\Desktop\Dealflow\venv\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\ARFATS~1\Desktop\Dealflow\venv\lib\site-packages\flask_restful\__init__.py", line 477, in wrapper
resp = resource(*args, **kwargs)
File "C:\Users\ARFATS~1\Desktop\Dealflow\venv\lib\site-packages\flask_jwt\__init__.py", line 176, in decorator
_jwt_required(realm or current_app.config['JWT_DEFAULT_REALM'])
File "C:\Users\ARFATS~1\Desktop\Dealflow\venv\lib\site-packages\flask_jwt\__init__.py", line 155, in _jwt_required
headers={'WWW-Authenticate': 'JWT realm="%s"' % realm})
JWTError: Authorization Required. Request does not contain an access token
I would like Flask-JWT to respond with the response which is there when Debug=True. However, I cannot use debug on Production servers. One way is to use my own jwt_required decorator. Is there any other way?Also, I would be happy to know what I am missing, if any. Thanks
You will need to add this setting to your flask app:
app.config['PROPAGATE_EXCEPTIONS'] = True
When debug is true, PROPAGATE_EXCEPTIONS is also set to true by default.
Perhaps consider checking out flask-jwt-extended instead (https://github.com/vimalloc/flask-jwt-extended), it takes care of the PROPAGATE_EXCEPTIONS for you. It aims to replace the abandoned flask-jwt library, and add some conviences when working with JWTs (such as refresh tokens, easily adding custom data to the JWTs, fresh vs non-fresh tokens, and more). Full disclosure, I'm the author of that extension.
Cheers.
I am trying to use python-request package to download a mass amount of files(like 10k+) from the web, each file size from several k to the largest as 100mb.
my script can run through fine for maybe 3000 files but suddenly it will hang.
I ctrl-c it and see it stuck at
r = requests.get(url, headers=headers, stream=True)
File "/Library/Python/2.7/site-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 456, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 559, in send
r = adapter.send(request, **kwargs)
File "/Library/Python/2.7/site-packages/requests/adapters.py", line 327, in send
timeout=timeout
File "/Library/Python/2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 493, in urlopen
body=body, headers=headers)
File "/Library/Python/2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 319, in _make_request
httplib_response = conn.getresponse(buffering=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1045, in getresponse
response.begin()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in begin
version, status, reason = self._read_status()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 365, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 476, in readline
data = self._sock.recv(self._rbufsize)
Here is my python code to do the download
basedir = os.path.dirname(filepath)
if not os.path.exists(basedir):
os.makedirs(basedir)
r = requests.get(url, headers=headers, stream=True)
with open(filepath, 'w') as f:
for chunk in r.iter_content(1024):
if chunk:
f.write(chunk)
f.flush()
I am not sure what went wrong, if anyone has a clue, please kindly share some insights.
Thanks.
This is not a duplicate of the question that #alfasin linked in their comment. Judging by the (limited) traceback you posted, the request itself is hanging (the first line shows it was executing r = requests.get(url, headers=headers, stream=True)).
What you should do is set a timeout and catch the exception that is raised when the request times out. Once you have the URL try it in a browser or with curl to ensure it responds properly, otherwise remove it from your list of URLs to request. If you find the misbehaving URL, please update your question with it.
I faced a similar situation and it seems like a bug in the requests package was causing this issue. Upgrading to requests package 2.10.0 fixed it for me.
For your reference the change log for Requests 2.10.0 shows that the embedded urllib3 was updated to version 1.15.1 Release history
And the release history for urllib3 (Release history ) shows that version 1.15.1 included fixes for:
Chunked transfer encoding when requesting with chunked=True. (Issue #790)
Fixed AppEngine handling of transfer-encoding header and bug in Timeout defaults checking. (Issue #763)
I have the following celery task:
#task
def get_users_facebook_as_profile_icon(user_id, facebook_id):
logger.info('Grabbing users facebook picture')
url = "http://graph.facebook.com/%s/picture?type=large" % facebook_id
import requests
response = requests.get(url)
if response.status_code != 200:
raise Exception("Could not get facebook profile picture")
...
I have more after this, but I keep getting the following error:
"AssertionError('PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()',)"
Task was called with args: (3246, 17500596) kwargs: {}.
The contents of the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 437, in __protected_call__
return self.run(*args, **kwargs)
File "/home/ubuntu/mounzawebsite/mounza/celery_tasks/login_registration.py", line 42, in get_users_facebook_as_profile_icon
hashname = user.generate_picture_name()
File "/home/ubuntu/mounzawebsite/mounza/web/models.py", line 515, in generate_picture_name
return generate_random_name(None)
File "/home/ubuntu/mounzawebsite/mounza/web/models.py", line 40, in generate_random_name
str(random.randint(1, 99982098098908237)) +
File "/usr/lib/python2.7/dist-packages/Crypto/Random/__init__.py", line 41, in get_random_bytes
return _UserFriendlyRNG.get_random_bytes(n)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 213, in get_random_bytes
return _get_singleton().read(n)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 163, in read
return _UserFriendlyRNG.read(self, bytes)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 122, in read
self._check_pid()
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 138, in _check_pid
raise AssertionError("PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()")
AssertionError: PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()
I tried digging into this online, not able to find the root cause. but this is the only task where this error occurs. The only difference is that i'm downloading an image from Facebook, but I never see this issue anywhere else, including other tasks where I download images.
The URL works perfectly if I do it through a web browser, but it's only via this task it fails. Is there anything else that could contribute to this??
I have exhausted all attempts in fixing this :(
Here is why:
http://comments.gmane.org/gmane.comp.python.amqp.celery.user/3664
always run teh below:
Crypto.Random.atfork()
When a new worker process is initialized. Done and done.
I'm currently creating a spreadsheet using xlwt and trying to export it out as an HttpResponse in django for a user to download. My code looks like this:
response = HttpResponse(mimetype = "application/vnd.ms-excel")
response['Content-Disposition'] = 'attachment; filename = %s +".xls"' % u'Zinnia_Entries'
work_book.save(response)
return response
Which seems to be the right way to do it, but I'm getting a:
Traceback (most recent call last):
File "C:\dev\workspace-warranty\imcom\imcom\wsgiserver.py", line 1233, in communicate
req.respond()
File "C:\dev\workspace-warranty\imcom\imcom\wsgiserver.py", line 745, in respond
self.server.gateway(self).respond()
File "C:\dev\workspace-warranty\imcom\imcom\wsgiserver.py", line 1927, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "C:\dev\workspace-warranty\3rdparty\django\core\servers\basehttp.py", line 674, in __call__
return self.application(environ, start_response)
File "C:\dev\workspace-warranty\3rdparty\django\core\handlers\wsgi.py", line 252, in __call__
response = middleware_method(request, response)
File "C:\dev\workspace-warranty\imcom\imcom\seo_mod\middleware.py", line 33, in process_response
response.content = strip_spaces_between_tags(response.content.strip())
File "C:\dev\workspace-warranty\3rdparty\django\utils\functional.py", line 259, in wrapper
return func(*args, **kwargs)
File "C:\dev\workspace-warranty\3rdparty\django\utils\html.py", line 89, in strip_spaces_between_tags
return re.sub(r'>\s+<', '><', force_unicode(value))
File "C:\dev\workspace-warranty\3rdparty\django\utils\encoding.py", line 88, in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xd0 in position 0: invalid continuation byte. You passed in
(I left off the rest because I get a really long line of this \xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00 kind of stuff)
Do you guys have any ideas on something that could be wrong with this? Is is it because some of my write values look like this:
work_sheet.write(r,#,information) where information isn't cast to unicode?
response['Content-Disposition'] = 'attachment; filename = %s +".xls"' % u'Zinnia_Entries'
should just be
response['Content-Disposition'] = 'attachment; filename = %s.xls' % u'Zinnia_Entries'
without quotes around .xls otherwise the output will be
u'attachment; filename = Zinnia_Entries +".xls"'
So try changing that.
But also check out this answer. It has a really helpful little function for outputing xls files.
django excel xlwt
Solved the problem. Apparently someone had put some funky middleware stuff in that was hacking apart and appending and adding, ect. ect. to the file. When it shouldn't.
Anyway, with it gone the file exports perfectly.
#Storm - Thank you for all the help!