[!] Error: Expected a '--url' parameter.

This is the place for queries that don't fit in any of the other categories.

[!] Error: Expected a '--url' parameter.

Postby xoziggieox » Fri Apr 04, 2014 5:21 am


I have a little code to do a Google search that someone made me. It works in dos but I'd like to also use it in the Python program. I am not sure how to define the --url parameter though so that it executes properly. I was wondering what I should do to define it. I've tried url = and that didn't quite work. Here is part of the code:
Code: Select all
def main():

   parser = argparse.ArgumentParser()
   parser.add_argument("-u", "--url", help="| The URL to scrape on.")
   parser.add_argument("-n", "--num", type=int, help="| The number of results to be shown.")
   parser.add_argument("-s", "--save", type=bool, help="| If the URLs are going to be saved in a local file.")
   args = parser.parse_args()

   if args.url == None:
      print "[!] Error: Expected a \'--url\' parameter."
      if args.num == None:
         global num
         num = 10
         num = args.num
Last edited by Yoriz on Fri Apr 04, 2014 5:27 am, edited 1 time in total.
Reason: First post lock
Posts: 1
Joined: Fri Apr 04, 2014 5:17 am

Re: [!] Error: Expected a '--url' parameter.

Postby Yoriz » Fri Apr 04, 2014 5:28 am

Hi, welcome to the forum, please read the 'new users read this' link in my signature if you haven't already.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: [!] Error: Expected a '--url' parameter.

Postby stranac » Fri Apr 04, 2014 9:47 am

You would have to define the variables yourself instead of using argparse, which takes them from the command line(you can see exactly how it works in the linked docs).
Also, there's some yucky stuff going on in that code, like the use of globals, exiting with code 0 on error...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 4 guests