【问题标题】:I am trying to make an URL shortener and I am facing this problem我正在尝试制作 URL 缩短器,但我遇到了这个问题
【发布时间】:2021-12-25 08:31:56
【问题描述】:

这是python代码:

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

print(x)

这是错误: module 'pyshorteners' has no attribute 'tinyurl'

【问题讨论】:

    标签: python-3.x tinyurl


    【解决方案1】:

    替换

    shortner=p.tinyurl.short(link)
    

    shortner=p.Shortener()
    

    取自此处的示例:https://pyshorteners.readthedocs.io/en/latest/

    【讨论】:

      【解决方案2】:

      那是因为 pyshorteners 没有属性 tinyurl 请尝试改用文档中的示例 (https://pyshorteners.readthedocs.io/en/latest/apis.html#tinyurl-com)

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

      【讨论】:

        【解决方案3】:

        您必须使用 pyshorteners 中的 Shortener()。要解决此问题,您可以使用以下代码:

        from pyshorteners import *
        
        print(Shortener().tinyurl.short('http://www.google.com'))
        

        【讨论】:

          猜你喜欢
          • 2022-11-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-09-02
          • 2010-11-09
          • 1970-01-01
          相关资源
          最近更新 更多