1

this is my code: i don't know what is this error can someone help or explain me what is this?


import urllib, json
import requests
from selenium import webdriver
import time


def look_for_new_video():

    api_key = "AIzaSyAsYUSACp5yxSa_KF5W3EM2mW4gvtqe0zw"
    channel_id = "UCrMT-qEr5f7CN6osiiTS6Rg"
    base_video_url = 'https://www.youtube.com/watch?v='
    base_search_url = 'https://www.googleapis.com/youtube/v3/search?'

    url = base_search_url + 'key={}&channelId={}&part=snippet,id&order=date&maxResults=1'.format(api_key, channel_id)
    inp = urllib.request(url)
    resp = json.load(inp)

    vidID= resp['items'][0]['id']['videoId']

    video_exists = False
    with open('videoid.json', 'r') as json_file:
        data = json.load(json_file)
        if data['videoId'] != vidID:
            driver = webdriver.Firefox()
            driver.get(base_video_url + vidID)
            video_exists = True

    if video_exists:
        with open('videoid.json', 'w') as json_file:
            data = {'videoId' : vidID}
            json.dump(data, json_file)

try:
    while True:
        look_for_new_video()
        time.sleep(10)
except KeyboardInterrupt:
    print('stopping')



i don't know what is this error can someone help or explain me what is this?

so i don't know why but this error is bugging me all day cam someone help me out: TypeError: 'module' object is not callable

4
  • 1
    Can you add the whole error trace? This can often help you track down the issue Commented May 24, 2020 at 19:50
  • This is the number 1 problem with stackoverflow python questions. People won't post python traceback messages. Python showed you the line with the error. Why make it hard? Commented May 24, 2020 at 20:03
  • if i add this 'inp = urllib.request.Request(url)' it shows this error: 'AttributeError: 'Request' object has no attribute 'read'' Commented May 24, 2020 at 20:14
  • @tdelaney Everyone makes that mistake. As long as you're learning from it :) Commented May 24, 2020 at 20:20

1 Answer 1

2

Looking over this briefly it looks like the error is with your request

inp = urllib.request(url)

should be

inp = urllib.request.Request(url)

Sign up to request clarification or add additional context in comments.

7 Comments

if i add this 'inp = urllib.request.Request(url)' it shows this error: 'AttributeError: 'Request' object has no attribute 'read''
Again, can you add the whole error? When you add the whole error there's a bit more information you can look at to help yourself determine the source of the issue. For example Traceback (most recent call last): File "G:/.../py/stack_exchange.py", line 942, in <module> look_for_new_video() File "G:/.../py/stack_exchange.py", line 922, in look_for_new_video inp = urllib.request(url) TypeError: 'module' object is not callable This error shows you the problem is happening at line 922, as shown in the traceback
this is the whole error: File "C:\Users\lagis\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 293, in load return loads(fp.read(), AttributeError: 'Request object has no attribute 'read'
@Lagis Looks like the urllib.request.Request(url) is not returning a JSON document. You might need to read up on the interaction and types
yeh, but i don't know what to do with this and how to fix it "[docs.python.org/3/library/json.html#json.load] " cuz im new to programing
|

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.