I am trying to access a path parameter using chalice but it's giving me a syntax error.
py file
#app.route('/someValue/{indicator}', methods=['GET']
def get_indicator_value(indicator):
Gives me this error mentioned below:
[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'test': invalid syntax (test.py, line 74)
Traceback (most recent call last):
File "/var/task/test.py" Line 74
def some_value(indicator):
What am I missing here ?
In the first line, you are missing the ) at the end. This is the fixed code:
#app.route('/someValue/{indicator}', methods=['GET'])
def get_indicator_value(indicator):
Related
I am using poetry and sys.argv.
I wrote the code in a OOP manner.
While I am running code from CLI, I am getting an error as shown below.
Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: main() missing 1 required positional argument: 'self'
I am taking argument from CLI and passing it to my script as mentioned below.
list_of_ticker = sys.argv[1].split(',')
print(list_of_ticker)
foo = CalculateEtfsYahoo(list_of_ticker)
foo.main()
FYI,
The code is working, only after expected output I am getting above mentioned error.
Also, I have added the module.pakage:class.function in pyproject.toml as shown below.
[tool.poetry.scripts] findata = "investment.ParseFinData:CalculateEtfsYahoo.main"
When I am replacing above point 2 with "module.package:class"
[tool.poetry.scripts] findata = "investment.ParseFinData:CalculateEtfsYahoo"
And giving CLI command like this: poetry run findata.main <argument>
then, I am getting error as
Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: CalculateEtfsYahoo() missing 1 required positional argument: 'list_of_ticker'
I do not know how to get rid of this error.
if everyrthing is working and you just want to get rid of the error you could use
import warnings
warnings.filterwarnings("ignore", category=TypeError) #I'm not sure this is the correct category but change it if needed.
I'm using the DiscoveryV1 python library to try to create a new collection in my WDS environment. I have the following code:
from watson_developer_cloud import DiscoveryV1
discovery = DiscoveryV1(
username = "username goes here",
password = "password goes here",
version = "version goes here")
conf_id ='valid configuration_id'
env_id = 'valid environment_id'
new_col = discovery.create_collection(env_id, 'TestV2', configuration_id=conf_id)
The final line of the above block throws the following error:
watson_developer_cloud.watson_developer_cloud_service.WatsonException: Error: Unsupported Media Type, Code: 415
Full stack trace:
Traceback (most recent call last):
File "uploadCorpus.py", line 23, in <module>
new_col = discovery.create_collection(env_id, 'TestV2', configuration_id=conf_id)
File "/home/Vito.Colano/Apps/anaconda2/lib/python2.7/site-packages/watson_developer_cloud/discovery_v1.py", line 227, in create_collection
accept_json=True)
File "/home/Vito.Colano/Apps/anaconda2/lib/python2.7/site-packages/watson_developer_cloud/watson_developer_cloud_service.py", line 324, in request
raise WatsonException(error_message)
watson_developer_cloud.watson_developer_cloud_service.WatsonException:
Error: Unsupported Media Type, Code: 41
This appears to be a bug in the Python SDK for Discovery. I, just now, opened a pull request to fix it.
https://github.com/watson-developer-cloud/python-sdk/pull/223
I forgot to say Thank you for asking this question. I only went looking for this bug and figured out what to fix because of your question.
Hi I am trying to rum a C *.o using python 2.6.5 as follows
import os
import sys
file_type = os.command('./file_type.o %s.txt 2>&1' % file_name)
And, it gives the error message :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'command'
Being a beginner this might be a very trivial question, I request for the direction / help.
There is no function named command in the os module, hence the error. You probably meant to call os.system() instead.
os.command() doesn't exist. It looks like you are looking for os.system()
os.command doesn't exist, using os.system instead.
I am trying to create a container within azure using the python sdk
when doing a test from the command interpreter, I ran the commands below and getting the following error:
>>> from azure.storage import BlobService
>>> blob_service = BlobService(account_name='kevtest', account_key='HFohNOxxxxxxxxxJzXao3NeSPOvozRvNFIQSVqO5yOT5+Aastl3sdcJKg+pKBk+oewM7Y6OuLDPbj7qq+7OQ==')
>>> blob_service.create_container('images')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/storage/blobservice.py", line 190, in create_container
_dont_fail_on_exist(ex)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/__init__.py", line 818, in _dont_fail_on_exist
raise error
azure.WindowsAzureError
>>>
That's likely an issue with your account name/key, but without the error message, I can't say for sure. You've censored your account key for this post, and so of course I can reproduce an authentication error.
Unfortunately the console can't display the full error message, but if you run it in an IDE or console that can display unicode strings without converting to ascii, you should be able to see the error message and confirm whether or not it's a problem with your account name/key.
I am trying to input a path using optparser in python. Unfortunately this piece of code keeps showing an error.
import optparse,os
parser = optparse.OptionParser()
parser.add_option("-p","--path", help = "Prints path",dest = "Input_Path", metavar = "PATH")
(opts,args) =parser.parse_args()
print os.path.isdir(opts.Input_Path)
Error :-
Traceback (most recent call last):
File "/Users/armed/Documents/Python_Test.py", line 8, in
print os.path.isdir(opts.Input_Path)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py", line 41, in isdir
st = os.stat(s)
TypeError: coercing to Unicode: need string or buffer, NoneType found
Any help is much appreciated !
That error is because opts.Input_Path is None, instead of being your path string/unicode.
Are you sure you are calling the script correctly? You should probably put in some error checking code in any case to make sure that if a user doesnt put -p, the program won't just crash.
Or, change it to a positional argument to make it 'required' by optparse:
http://docs.python.org/library/optparse.html#what-are-positional-arguments-for
Edit: Also optparse is deprecated, for a new project you probably want to use argparse.
I copied your script and ran it. Looks like you call your script in a wrong way:
$ python test.py /tmp
Traceback (most recent call last):
File "test.py", line 8, in <module>
print os.path.isdir(opts.Input_Path)
File "/usr/lib/python2.6/genericpath.py", line 41, in isdir
st = os.stat(s)
TypeError: coercing to Unicode: need string or buffer, NoneType found
but
$ python test.py --path /tmp
True