question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Error from cookiecutter: open() argument 6 must be str or None, not tuple

See original GitHub issue

Description:

When trying to create a SAM app template using sam init, it creates a folder with no content in it.

sam-app
├── events
├── hello_world
└── tests

3 directories, 0 files

When I ran sam init --debug it run an error

2022-07-14 02:53:58,674 | Baking a new template with cookiecutter with all parameters
2022-07-14 02:53:58,727 | Error from cookiecutter: open() argument 6 must be str or None, not tuple
2022-07-14 02:53:58,728 | Template is not provided in context, skip adding project type metric

Steps to reproduce:

$ sam init 

Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
        1 - Hello World Example
        2 - Multi-step workflow
        3 - Serverless API
        4 - Scheduled task
        5 - Standalone function
        6 - Data processing
        7 - Infrastructure event management
        8 - Machine Learning
Template: 1

Use the most popular runtime and package type? (Python and zip) [y/N]: N

Which runtime would you like to use?
        1 - dotnet6
        2 - dotnet5.0
        3 - dotnetcore3.1
        4 - go1.x
        5 - graalvm.java11 (provided.al2)
        6 - graalvm.java17 (provided.al2)
        7 - java11
        8 - java8.al2
        9 - java8
        10 - nodejs16.x
        11 - nodejs14.x
        12 - nodejs12.x
        13 - python3.9
        14 - python3.8
        15 - python3.7
        16 - python3.6
        17 - ruby2.7
        18 - rust (provided.al2)
Runtime: 14

What package type would you like to use?
        1 - Zip
        2 - Image
Package type: 2

Based on your selections, the only dependency manager available is pip.
We will proceed copying the template using pip.

Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: N

Project name [sam-app]: sam-app

Observed result:

user/project $ sam init --debug
2022-07-14 02:52:34,113 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-07-14 02:52:34,113 | Using config file: samconfig.toml, config environment: default
2022-07-14 02:52:34,113 | Expand command line arguments to:
2022-07-14 02:52:34,114 | --package_type=Zip --output_dir=. 

You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.

Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
        1 - Hello World Example
        2 - Multi-step workflow
        3 - Serverless API
        4 - Scheduled task
        5 - Standalone function
        6 - Data processing
        7 - Infrastructure event management
        8 - Machine Learning
Template: 1

Use the most popular runtime and package type? (Python and zip) [y/N]: N

Which runtime would you like to use?
        1 - dotnet6
        2 - dotnet5.0
        3 - dotnetcore3.1
        4 - go1.x
        5 - graalvm.java11 (provided.al2)
        6 - graalvm.java17 (provided.al2)
        7 - java11
        8 - java8.al2
        9 - java8
        10 - nodejs16.x
        11 - nodejs14.x
        12 - nodejs12.x
        13 - python3.9
        14 - python3.8
        15 - python3.7
        16 - python3.6
        17 - ruby2.7
        18 - rust (provided.al2)
Runtime: 14

What package type would you like to use?
        1 - Zip
        2 - Image
Package type: 2

Based on your selections, the only dependency manager available is pip.
We will proceed copying the template using pip.

Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: 

Project name [sam-app]: 
2022-07-14 02:53:35,233 | 
Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
2022-07-14 02:53:58,115 | Removing old repo at /home/user/.aws-sam/aws-sam-cli-app-templates
2022-07-14 02:53:58,225 | Copying from /tmp/tmpgbdazfe3/aws-sam-cli-app-templates to /home/user/.aws-sam/aws-sam-cli-app-templates

    -----------------------
    Generating application:
    -----------------------
    Name: sam-app
    Base Image: amazon/python3.8-base
    Architectures: x86_64
    Dependency Manager: pip
    Output Directory: .

    Next steps can be found in the README file at ./sam-app/README.md
    

    Commands you can use next
    =========================
    [*] Create pipeline: cd sam-app && sam pipeline init --bootstrap
    [*] Validate SAM template: sam validate
    [*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
    
2022-07-14 02:53:58,674 | Parameters dict created with input given
2022-07-14 02:53:58,674 | {'template': '/home/user/.aws-sam/aws-sam-cli-app-templates/python3.8-image/cookiecutter-aws-sam-hello-python-lambda-image', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'sam-app', 'runtime': 'python3.8', 'architectures': {'value': ['x86_64']}}}
2022-07-14 02:53:58,674 | Baking a new template with cookiecutter with all parameters
2022-07-14 02:53:58,727 | Error from cookiecutter: open() argument 6 must be str or None, not tuple
2022-07-14 02:53:58,728 | Template is not provided in context, skip adding project type metric

Expected result:

I expect it to create the sam app template folder with the necessary files present

sam-app
├── README.md
├── __init__.py
├── events
│   └── event.json
├── hello_world
│   ├── Dockerfile
│   ├── __init__.py
│   ├── app.py
│   └── requirements.txt
├── template.yaml
└── tests
    ├── __init__.py
    └── unit
        ├── __init__.py
        └── test_handler.py

4 directories, 11 files

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: WSL Ubuntu 20.04
  2. sam --version: SAM CLI, version 1.53.0
  3. AWS region:

Add --debug flag to command you are running

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sriram-mvcommented, Jul 27, 2022

On following up for this particular issue, it looks to be related to fixes that we made in updating cookiecutter to 2.1.1 . This PR fixes it, however its not yet released.

If you would like to still use the latest version of sam cli, you would need to edit runtime_config.json to have the latest commit from aws-sam-cli-app-templates repo. At this point in time the top commit hash is dca20ade1b290262b6457006b52abadeacdddaf8

The current bundled commit hash is 5df174d5a1855c62b4cc69698666c74fe758e68a through https://github.com/aws/aws-sam-cli/pull/3959/files

Once the latest version of sam cli is released this should be fixed.

0reactions
mildanielcommented, Aug 15, 2022

This issue should be fixed by 1.54.0 released on 8/15/2022. Please re-open this ticket if you still face this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: must be str, not tuple [duplicate] - Stack Overflow
output_to_receipt is a tuple, so you need to convert it to a string with str(output_to_receipt) or "".join(output_to_receipt) for example.
Read more >
TypeError: write() argument must be str, not tuple (Python)
The Python "TypeError: write() argument must be str, not tuple" occurs when we try to write a tuple object to a file using...
Read more >
2005-April.txt - Python mailing list
Result res0 is a non-null object. As far as I can understand the "Extending and Embedding the Python Interpreter" doc, res1 should work...
Read more >
fake-winreg - PyPI
TypeError: CreateKey() argument 2 must be str or None, not int >>> # Test subkey=None with key as predefined HKEY - that should...
Read more >
cookiecutter Documentation
You don't have to know/write Python code to use Cookiecutter. • Works with Python 2.7, 3.5, 3.6, 3.7, 3.8 ,PyPy and PyPy3. •...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found