Syntax error when using snakemd in AWS Lambda - python

I am currently using snakemd to create a markdown template.
When I am using it locally, the file is created normally.
In Lambda, I get the following error:
Syntax error in module: invalid syntax (generator.py, line 604)
I checked the line and nothing seems to be off.
Anyone ever came across the same problem?

Assignment expressions such as the following (here) are new in Python 3.8:
items := inline_text._text.split(target)
Upgrade your Lambda runtime environment from Python 3.7.

Related

My Python script using Paramiko runs perfectly in the IDE (PyCharm) and command line but doesn't run on AWS Lambda

I'm writing a Python script (Python version 3.7 on Mac OS 10.15.7) that I intend to put on our AWS Lambda server and the script uses Paramiko. It runs perfectly fine in my IDE and on the command line, but when I try to run it on Lambda, I get this error message:
{
"errorMessage": "Unable to import module 'lambda_function': libs/bcrypt/_bcrypt.abi3.so: invalid ELF header",
"errorType": "Runtime.ImportModuleError"
}
I found this similar-looking question on Stack Overflow, but the answers to that question don't seem to apply to this situation as they relate to Windows and to a different Python library. But maybe there's something I missed?
Edit: Something that may be relevant is that my computer has Python 3.9 installed but I'm trying to write this in Python 3.7.
I solved this by creating a layer for PySFTP/Paramiko.
The reason this is happening is because when you ran "pip install paramiko" it installs it according to your OS and computer architecture. This may not be the same architecture as what your Lambda function is running on.
I would recommend following this guide to properly create layers to ship with Lambda functions: https://oznetnerd.com/2020/11/11/lambda-packaging-the-right-way/

Invalid Syntax in F string Python 3 [duplicate]

I tried this code, following along with a tutorial:
my_name = 'Zed A. Shaw'
print(f"Let's talk about {my_name}.")
But I get an error message highlighting the last line, like so:
print(f"Let's talk about {my_name}.")
^
SyntaxError: invalid syntax
Why?
If you get an error like this from someone else's code, do not try to fix it yourself - the other project simply does not support your Python version (One example: Using pytesseract on Python 2.7 and Windows XP). Look for an alternative instead, or check the project's documentation or other support resources for a workaround.
In particular, the built-in pip package manager has an issue where newer versions of pip require a newer Python version, so old installations cannot upgrade pip past a certain point. See Installing pip is not working in python < 3.6 or Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}") for details.
If an external tool warns about the problem even though Python supports the feature, update the tool. See Getting invalid syntax error when using Pylint but code runs fine for an example.
This question is specifically about the situation where any attempt to use f-strings fails (the ^ in the error message will point at the closing quote). For common problems with specific f-string syntax, see How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?, f-string formula inside curly brackets not working, Discord.py - SyntaxError f-string: empty expression not allowed, How to use newline '\n' in f-string to format output in Python 3.6?.
For details on alternate approaches to string formatting, see How do I put a variable’s value inside a string (interpolate it into the string)?.
I think you have an old version of python. try upgrading to the latest version of python. F-string literals have been added to python since python 3.6. you can check more about it here
This is a python version problem.
Instead of using
print(f"Let's talk about {my_name}."
use
print("Let's talk about {}.".format(my_name))
in python2.
Your code works on python3.7.
Check it out here:
my_name= "raushan"
print(f"Let's talk about {my_name}.")
https://repl.it/languages/python3
Python Interpreter causes the following issue because of the wrong python version you calling when executing the program as f strings are part of python 3 and not python 2. You could do this python3 filename.py, it should work. To fix this issue, change the python interpreter from 2 to 3. 
f-strings were added in python 3.6. In older python versions, an f-string will result in a syntax error.
If you don't want to (or can't) upgrade, see How do I put a variable inside a String in Python? for alternatives to f-strings.
I think this is due to the old version. I have tried in the new version and the executing fine. and the result is as expected.
I believe the problem you are having here is down to you using python 2 without realizing it. if you haven't set it up on your machine to have python 3 as your default version you should execute python3 in your terminal instead of the standard 'python' command.
I had this problem so hopefully, this answer can be of help to those looking for it.
I think they had typed
python file.py
to run the program in the Mac or linux that runs the python 2 version directly because OS defaultly contain python 2 version, so we needed to type
python3 file.py
That's the solution for the problem
python2 and python3 running command

jira-python...get_server_info=True...invalid syntax

Out of the blue, I'm faced with the following error when I deploy my code to kubernetes running python 3.6.6 and jira==1.0.15:
from jira import JIRA
File "/usr/local/lib/python3.7/site-packages/jira/__init__.py", line 10, in <module>
from jira.client import Comment # noqa: E402
File "/usr/local/lib/python3.7/site-packages/jira/client.py", line 337
validate=False, get_server_info=True, async=False, logging=True, max_retries=3, proxies=None,
^
SyntaxError: invalid syntax
It works just fine, however, in my local environment running mac/docker python 3.6.5 and jira==1.0.15.
I've seen the issue being discussed here: https://github.com/pycontribs/jira/issues/603. But the difference in my situation is that I'm not using python 3.7 and the up arrow ^ in my error is not pointing to async=False but it's pointing to get_server_info=True instead.
I've been pulling my hair out over this one for the past several hours. Can any shed any light on a fix for this issue?
The SyntaxError arrow isn't always exact (usually near the actual cause of the error), and as you can see from the directory name usr/local/lib/python3.7/, you are running Python 3.7. async and await are reserved keywords as of this version, so when the name async or await is used in purposes designed otherwise, a SyntaxError will be raised.
From a look of the link you linked, in the past week, the developers are working hard to fix this issue. It might not be complete fixed yet, but you can install the developmental version of your package by following the steps under "Development" https://github.com/pycontribs/jira/blob/master/README.rst#Development.
Or, for coarse, you can install any version of Python < 3.7.

Python3 print(f" ...") issue with format method [duplicate]

I tried this code, following along with a tutorial:
my_name = 'Zed A. Shaw'
print(f"Let's talk about {my_name}.")
But I get an error message highlighting the last line, like so:
print(f"Let's talk about {my_name}.")
^
SyntaxError: invalid syntax
Why?
If you get an error like this from someone else's code, do not try to fix it yourself - the other project simply does not support your Python version (One example: Using pytesseract on Python 2.7 and Windows XP). Look for an alternative instead, or check the project's documentation or other support resources for a workaround.
In particular, the built-in pip package manager has an issue where newer versions of pip require a newer Python version, so old installations cannot upgrade pip past a certain point. See Installing pip is not working in python < 3.6 or Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}") for details.
If an external tool warns about the problem even though Python supports the feature, update the tool. See Getting invalid syntax error when using Pylint but code runs fine for an example.
This question is specifically about the situation where any attempt to use f-strings fails (the ^ in the error message will point at the closing quote). For common problems with specific f-string syntax, see How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?, f-string formula inside curly brackets not working, Discord.py - SyntaxError f-string: empty expression not allowed, How to use newline '\n' in f-string to format output in Python 3.6?.
For details on alternate approaches to string formatting, see How do I put a variable’s value inside a string (interpolate it into the string)?.
I think you have an old version of python. try upgrading to the latest version of python. F-string literals have been added to python since python 3.6. you can check more about it here
This is a python version problem.
Instead of using
print(f"Let's talk about {my_name}."
use
print("Let's talk about {}.".format(my_name))
in python2.
Your code works on python3.7.
Check it out here:
my_name= "raushan"
print(f"Let's talk about {my_name}.")
https://repl.it/languages/python3
Python Interpreter causes the following issue because of the wrong python version you calling when executing the program as f strings are part of python 3 and not python 2. You could do this python3 filename.py, it should work. To fix this issue, change the python interpreter from 2 to 3. 
f-strings were added in python 3.6. In older python versions, an f-string will result in a syntax error.
If you don't want to (or can't) upgrade, see How do I put a variable inside a String in Python? for alternatives to f-strings.
I think this is due to the old version. I have tried in the new version and the executing fine. and the result is as expected.
I believe the problem you are having here is down to you using python 2 without realizing it. if you haven't set it up on your machine to have python 3 as your default version you should execute python3 in your terminal instead of the standard 'python' command.
I had this problem so hopefully, this answer can be of help to those looking for it.
I think they had typed
python file.py
to run the program in the Mac or linux that runs the python 2 version directly because OS defaultly contain python 2 version, so we needed to type
python3 file.py
That's the solution for the problem
python2 and python3 running command

Syntax Error in Python Request Library when Using on My Test server

I'm using Python Request Library in one of my projects. Everything works fine on my local system where I have Python 2.6 and Django 1.2.3.
I have created the same environment for my Test server(Python 2.6 and Django 1.2.3 and is using WSGI 3.2). Now I get some weird syntax errors. For example:
line 266
result.append((k.encode('utf-8') if isinstance(k, unicode) else k,
^
SyntaxError: invalid syntax*
Here's another:
from .config import settings
^
SyntaxError: invalid syntax*
I'm guessing it's something because of wsgi but not sure exactly. Can someone please help me to solve this issue.
Thanks
This errors mean that actually you are not using Python 2.6. Probably Python 2.4 is also installed on you environment and it is used to execute your code.
I'm guessing your webserver (such as apache) is using an older version of python, rather than the python 2.6 environment you setup.

Categories