0

I am trying to create GitLab projects through GitLab CI pipeline by importing the GitLab export tar.gz file using python-gitlab library. The new project gets created but does not get initialized with the configuration in the GitLab export file. Instead, I get "Attempted to initialize RESTObject with a non-dictionary value" error. As an alternative, I tried creating a blank project and initialize it with the files that I need, such as Readme.md and .gitlab-ci.yml, but getting the same error still.

First I tried creating a new project by importing GitLab export file from the source project, where I am running this code in a CI container:

# Read file from the repository where this CI runs
with open('scripts/new_export.tar.gz', 'rb') as f:
                import_file_content = f.read()

# Create project by importing the above gitlab export file
create_project = gl.projects.import_project(
                import_file_content,
                path=project_name,
                namespace_id=gitlab_namespace_id
                )

I confirmed that this creates the project, but does not apply the gitlab export file (import_file_content). Instead, it throws the error "Attempted to initialize RESTObject with a non-dictionary value. This likely indicates an incorrect or malformed server response.".

Then, I thought of creating a blank project and uploading the files I need instead of using gitlab export file to do all that:

# Create new blank project
create_project = gl.projects.create({'name': project_name, 'namespace_id': gitlab_namespace_id})

# Get the project ID for subsequent calls
gitlab_project_id = create_project.id

# Use the new project's ID for subsequent calls
new_project = gl.projects.get(gitlab_project_id)

I confirmed that this created the new GitLab project as well. Then,

# Read the readme.md file from the source repository where this CI runs
readmeFile = open("assets/README.md", "rt").read()

# Create a file in the new GitLab project
new_project.files.create({'file_path': 'README.md',
                          'branch': 'main',
                          'content': readmeFile,
                          'author_email': '[email protected]',
                          'author_name': 'yourname',
                          'commit_message': 'Create testfile'})

Still, I am getting the same error I got earlier "Attempted to initialize RESTObject with a non-dictionary value. This likely indicates an incorrect or malformed server response.".

Am I doing something wrong or is it an issue with GitLab?

1
  • Can you please provide the full stacktrace? Does your project have branch protection rules (for example, rules inherited from an ancestor namespace setting)? Commented Sep 28, 2023 at 17:50

1 Answer 1

0

This error may indicate that the URL endpoint you gave isn't usable.

I solved this issue by using as endpoint:

https://gitlab.com/api/v4/

or if self-hosted

https://myCompagny.example.com/

instead of:

https://gitlab.com/api/v4/somethingElse/etc

or

https://myCompagny.example.com/somethingElse/etc
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.