Getting Youtube data using Python

2024/9/8 10:41:31

I'm trying to learn how to analyze social media data available on the web and I'm starting with Youtube.

from apiclient.errors import HttpError
from outh2client.tools import argparser
from apiclient.discovery import build
import pandas as pd
DEVELOPER_KEY = "AIzaSyB_F1mCrDydEbGUosnZES-NW-mg1CaOyjI"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
argparser.add_argument("--q", help="Search term", default="apple product")
argparser.add_argument("--max-results", help="Max results", default=50)
args = argparser.parse_args()
options = args

And I get this error.

ArgumentError                             Traceback (most recent call last)
<ipython-input-37-ebbf58549b73> in <module>()
----> 1 argparser.add_argument("--q", help="Search term", default="apple product")2 argparser.add_argument("--max-results", help="Max results", default=50)3 args = argparser.parse_args()4 options = args/usr/lib/python2.7/argparse.py in add_argument(self, *args, **kwargs)1306                 raise ValueError("length of metavar tuple does not match nargs")1307 
-> 1308         return self._add_action(action)1309 1310     def add_argument_group(self, *args, **kwargs):/usr/lib/python2.7/argparse.py in _add_action(self, action)1680     def _add_action(self, action):1681         if action.option_strings:
-> 1682             self._optionals._add_action(action)1683         else:1684             self._positionals._add_action(action)/usr/lib/python2.7/argparse.py in _add_action(self, action)1507 1508     def _add_action(self, action):
-> 1509         action = super(_ArgumentGroup, self)._add_action(action)1510         self._group_actions.append(action)1511         return action
/usr/lib/python2.7/argparse.py in _add_action(self, action)1320     def _add_action(self, action):1321         # resolve any conflicts
-> 1322         self._check_conflict(action)1323 1324         # add to actions list/usr/lib/python2.7/argparse.py in _check_conflict(self, action)1458         if confl_optionals:1459             conflict_handler = self._get_handler()
-> 1460             conflict_handler(action, confl_optionals)1461 1462     def _handle_conflict_error(self, action, conflicting_actions):/usr/lib/python2.7/argparse.py in _handle_conflict_error(self, action, conflicting_actions)1465                                      for option_string, action1466                                      in conflicting_actions])
-> 1467         raise ArgumentError(action, message % conflict_string)1468 1469     def _handle_conflict_resolve(self, action, conflicting_actions):ArgumentError: argument --q: conflicting option string(s): --q

I'm using a tutorial for this but I get an error.

Answer

It looks like the parser that you import

from outh2client.tools import argparser

already has defined a -q argument. You can check that by looking at its code, or by doing a argparser.print_help() (before adding anything yourself).

So the simplest solution is to choose another name for your argument.

The relevant docs are

https://docs.python.org/3.4/library/argparse.html#conflict-handler

found by looking up 'conflict' on that page.

The parser defined on https://github.com/google/oauth2client/blob/master/oauth2client/tools.py does not have a -q argument. Is this your source? I assume the missing a is a spelling error.

https://en.xdnf.cn/q/72570.html

Related Q&A

matplotlib does not show legend in scatter plot

I am trying to work on a clustering problem for which I need to plot a scatter plot for my clusters.%matplotlib inline import matplotlib.pyplot as plt df = pd.merge(dataframe,actual_cluster) plt.scatte…

Correct usage of asyncio.Conditions wait_for() method

Im writing a project using Pythons asyncio module, and Id like to synchronize my tasks using its synchronization primitives. However, it doesnt seem to behave as Id expect.From the documentation, it se…

displaying newlines in the help message when using pythons optparse

Im using the optparse module for option/argument parsing. For backwards compatibility reasons, I cant use the argparse module. How can I format my epilog message so that newlines are preserved?In th…

How to use a learnable parameter in pytorch, constrained between 0 and 1?

I want to use a learnable parameter that only takes values between 0 and 1. How can I do this in pytorch? Currently I am using: self.beta = Parameter(torch.Tensor(1)) #initialize zeros(self.beta)But I…

generating a CSV file online on Google App Engine

I am using Google App Engine (python), I want my users to be able to download a CSV file generated using some data from the datastore (but I dont want them to download the whole thing, as I re-order th…

Python equivalence of Rs match() for indexing

So i essentially want to implement the equivalent of Rs match() function in Python, using Pandas dataframes - without using a for-loop. In R match() returns a vector of the positions of (first) matches…

Why doesnt Pydantic validate field assignments?

I want to use Pydantic to validate fields in my object, but it seems like validation only happens when I create an instance, but not when I later modify fields. from pydantic import BaseModel, validato…

Format OCR text annotation from Cloud Vision API in Python

I am using the Google Cloud Vision API for Python on a small program Im using. The function is working and I get the OCR results, but I need to format these before being able to work with them.This is …

Does pybtex support accent/special characters in .bib file?

from pybtex.database.input import bibtex parser = bibtex.Parser() bibdata = parser.parse_file("sample.bib")The above code snippet works really well in parsing a .bib file but it seems not to …

How do I count specific values across multiple columns in pandas

I have the DataFrame df = pd.DataFrame({colA:[?,2,3,4,?],colB:[1,2,?,3,4],colC:[?,2,3,4,5] })I would like to get the count the the number of ? in each column and return the following output - colA…