How to troubleshoot a python-bilibili error

Source: Internet
Author: User
Before getting the room number, we should first solve the bug left over from the previous article, that is, the entered room number is not a problem because the number does not exist and the corresponding room number does not exist. Before getting the room number, we should first solve the bug left over from the previous article, that is, the entered room number is not a problem because the number does not exist and the corresponding room number does not exist.

The entered room number is not a number:

In python, what you enter must be a string. although you enter a number, the type is str.


RoomId = input ('Enter the room number :')

Using the code in the previous article, let's test it.

RoomId = input ('Enter the room number: ') while not roomId. isdigit (): print ("The number format is incorrect. please enter it again! ") RoomId = input ('Enter the room number: ') roomUrl = 'http: // live.bilibili.com/'+ str (roomId)

:

In the last sentence, urllib. error. HTTPError: HTTP Error 404: Not Found.

Webpage 404, no webpage found. The webpage address you entered does not exist. Try-try T to solve this error.

Ideas:

1. accessing a website does not know whether it is in

2. try to access this address.

3. if an error occurs, enter the URL again.

4. re-enter the website address and start from entering the room number.

5. a large cycle starts with an error on the website. a small cycle is used to determine the room number.

6. if the entered URL exists, you need to jump out of this cycle.

Code:

While True: roomId = input ('Enter the room number: ') while not roomId. isdigit (): print ("The number format is incorrect. please enter it again! ") RoomId = input ('Enter the room number: ') roomUrl = 'http: // live.bilibili.com/'+ str (roomId) try: webPage = urllib. request. urlopen (roomUrl) break failed t: print ('error! ')

However, in this way, the user experience is not good, and we do not know where the error is, so we take the specific reason


Failed T urllib. error. HTTPError as reason: print ('url error! '+ Str (reason ))

:

The above is a detailed explanation of the solution to the python-bilibili error. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.