Error When Making a PyPi Package

Question:
So I am making a Python Framework that I want to publish on PyPi so people can easily import the code without having to use the source code.
But when I am putting the commands in the shell →

poetry new vial
cd vial
poetry update

The error happens and says Illegal character ‘\n’ (line 4, column 115)
But I can’t seem to find/fix the error.

Repl link:
https://replit.com/@SalladShooter/VIAL-Module

__init__.py

from werkzeug.exceptions import HTTPException, NotFound
from werkzeug.middleware.shared_data import SharedDataMiddleware
from werkzeug.routing import Map, Rule
from werkzeug.serving import run_simple
from werkzeug.wrappers import Request, Response

class App:

    def __init__(self):
        self.url_map = Map()
        self.view_functions = {}
        self.html_content = []

    def route(self, rule, **options):
        def decorator(function):
            self.url_map.add(Rule(rule, endpoint=function.__name__))
            self.view_functions[function.__name__] = function
            return function

        return decorator

    def dispatch_request(self, request):
        adapter = self.url_map.bind_to_environ(request.environ)
        try:
            endpoint, values = adapter.match()
            return self.view_functions[endpoint](request, **values)
        except HTTPException as e:
            return e

    def __call__(self, environ, start_response):
        request = Request(environ)
        response = self.dispatch_request(request)
        return response(environ, start_response)

    def run(self, host='0.0.0.0', port=5000):
        app = SharedDataMiddleware(self, {'/static': 'static'})
        run_simple(host, port, app)

    def reload_content(self, new_content):
        self.html_content = new_content

# Copyright (c) 2024 SalladShooter

class Tag:

    def __init__(self, name, text=''):
        self.name = name
        self.attributes = []
        self.children = []
        self.text = text

    def attribute(self, key, value):
        self.attributes.append((key, value))
        return self

    def id(self, value):
        self.attributes.append(('id', value))
        return self

    def add_children(self, *tags):
        self.children.extend(tags)
        return self

    def __str__(self):
        attrs = ' '.join([f'{k}="{v}"' for k, v in self.attributes])
        children = ''.join(map(str, self.children)
        return f'<{self.name} {attrs}>{self.text}{children}</{self.name}>'

class Tags:

    class div(Tag):
        def __init__(self, text=''):
            super().__init__('div', text)

    class address(Tag):
        def __init__(self, text=''):
            super().__init__('address', text)


    class article(Tag):
        def __init__(self, text=''):
            super().__init__('article', text)

    class aside(Tag):
        def __init__(self, text=''):
            super().__init__('aside', text)

    class footer(Tag):
        def __init__(self, text=''):
            super().__init__('footer', text)

    class header(Tag):
        def __init__(self, text=''):
            super().__init__('header', text)

    class hgroup(Tag):
        def __init__(self, text=''):
            super().__init__('hgroup', text)

    class main(Tag):
        def __init__(self, text=''):
            super().__init__('main', text)

    class section(Tag):
        def __init__(self, text=''):
            super().__init__('section', text)

    class search(Tag):
        def __init__(self, text=''):
            super().__init__('search', text)

    class figure(Tag):
        def __init__(self, text=''):
            super().__init__('figure', text)

    class blockquote(Tag):
        def __init__(self, text='', cite=''):
            super().__init__('blockquote', text)
            self.attribute('cite', cite)

    class p(Tag):
        def __init__(self, text=''):
            super().__init__('p', text)

    class h1(Tag):
        def __init__(self, text=''):
            super().__init__('h1', text)

    class h2(Tag):
        def __init__(self, text=''):
            super().__init__('h2', text)

    class h3(Tag):
        def __init__(self, text=''):
            super().__init__('h3', text)

    class h4(Tag):
        def __init__(self, text=''):
            super().__init__('h4', text)

    class h5(Tag):
        def __init__(self, text=''):
            super().__init__('h5', text)

    class h6(Tag):
        def __init__(self, text=''):
            super().__init__('h6', text)

    class span(Tag):
        def __init__(self, text=''):
            super().__init__('span', text)

    class dd(Tag):
        def __init__(self, text=''):
            super().__init__('dd', text)

    class dl(Tag):
        def __init__(self, text=''):
            super().__init__('dl', text)

    class dt(Tag):
        def __init__(self, text=''):
            super().__init__('dt', text)

    class figcaption(Tag):
        def __init__(self, text=''):
            super().__init__('figcaption', text)

    class hr(Tag):
        def __init__(self, text=''):
            super().__init__('hr', text)

    class menu(Tag):
        def __init__(self, text=''):
            super().__init__('menu', text)

    class ol(Tag):
        def __init__(self, text=''):
            super().__init__('ol', text)

    class pre(Tag):
        def __init__(self, text=''):
            super().__init__('pre', text)

    class ul(Tag):
        def __init__(self, text=''):
            super().__init__('ul', text)

    class li(Tag):
        def __init__(self, text=''):
            super().__init__('li', text)

    class a(Tag):
        def __init__(self, text='', href='#'):
            super().__init__('a', text)
            self.attribute('href', href)

    class img(Tag):
        def __init__(self, src='', alt=''):
            super().__init__('img')
            self.attribute('src', src)
            self.attribute('alt', alt)

    class table(Tag):
        def __init__(self, text=''):
            super().__init__('table', text)

    class tr(Tag):
        def __init__(self, text=''):
            super().__init__('tr', text)

    class th(Tag):
        def __init__(self, text=''):
            super().__init__('th', text)

    class td(Tag):
        def __init__(self, text=''):
            super().__init__('td', text)

    class form(Tag):
        def __init__(self, text=''):
            super().__init__('form', text)

    class input(Tag):
        def __init__(self, type='', value=''):
            super().__init__('input')
            self.attribute('type', type)
            self.attribute('value', value)

    class button(Tag):
        def __init__(self, text=''):
            super().__init__('button', text)

You accidently typed a newline on line 4-5 of vial/pyproject.toml, so if you delete that, it should work.

2 Likes

@Fairies0feast ok that worked, but after

poetry build
poetry publish

It throws an error and doesn’t ask for credentials like it normally does.

~/VIAL-Module/vial$ poetry publish
Publishing vial (0.2.0) to PyPI
- Uploading vial-0.2.0-py3-none-any.whl 100
- Uploading vial-0.2.0-py3-none-any.whl FAI
LED
HTTP Error 403: Invalid or non-existent auth entication information. See https://pypi.org /help/#invalid-auth for more information. I b'<html>\n <head>\n <title>403 Invalid or n on-existent authentication information. See https://pypi.org/help/#invalid-auth for more information. \n \n <body>\n <h1>403 Invalid or non-existent authentication information.
See https://pypi.org/help/#invalid-auth for more information. \n Access was denied to t his resource.<br/><br/>\nInvalid or non-exis tent authentication information. See https:/ /pypi.org/help/#invalid-auth for more inform ation. \n\n\n \n'
~/VIAL-Module/vial$ | 

Do you have 2FA enabled?
Is the version a new version?

Tbh I recommend using project tokens, even if you don’t have 2FA on.

1 Like

@Firepup650 how would I use project tokens (sorry for the dumb question, I have never used secrets/tokens before), also how would I use them for the publishing of the package?

@SalladShooter

  1. Go to https://pypi.org/manage/account/token/
  2. Login if you’re not
  3. Give the key a name, select the token’s scope (I suggest doing it per-project so that if it’s ever compromised the damage is minimal)
  4. (Technically optional, but I recommend it so you don’t have to remember the token) Set a secret called something like PYPI_TOKEN to the token pypi gave you
  5. Run poetry publish -u __token__ -p $PYPI_TOKEN, where $PYPI_TOKEN is the secret pointing to your token, or just paste the token there. (Do NOT change -u __token__, that is the correct username for all tokens)
  6. Profit
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.