'I am trying to make an URL shortener and I am facing this problem

This is the python code:

import pyshorteners as p
    
link=input("Enter the link: ")
shortner=p.tinyurl.short(link)
x=shortner.tinyurl.short(link)

print(x)

This is the error: module 'pyshorteners' has no attribute 'tinyurl'



Solution 1:[1]

Replace

shortner=p.tinyurl.short(link)

with

shortner=p.Shortener()

Taken from the example here: https://pyshorteners.readthedocs.io/en/latest/

Solution 2:[2]

That's because pyshorteners doesn't have an attribute tinyurl Try using the example from the documentation (https://pyshorteners.readthedocs.io/en/latest/apis.html#tinyurl-com) instead

import pyshorteners
s = pyshorteners.Shortener()
s.tinyurl.short('http://www.google.com')

Solution 3:[3]

you must use Shortener() from the pyshorteners. To solve this problem you can use the code below:

from pyshorteners import *

print(Shortener().tinyurl.short('http://www.google.com'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ScottMcC
Solution 2 SamBob
Solution 3 Mohammad Al Jadallah