Re: [Tutor] Thanks for the advise to tutor! HTTP Error 400 resolved
I have added below to the first line of the function and managed to ignore the space and solve it. Thank you for the hint! some_text=urllib.parse.quote_plus(some_text) On Tue, Feb 13, 2018 at 5:00 PM, wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > >1. Re: [Help] urllib.error.HTTPError: HTTP Error 400: Bad > Request (Peter Otten) > > > -- Forwarded message -- > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Cc: > Bcc: > Date: Tue, 13 Feb 2018 14:47:56 +0100 > Subject: Re: [Tutor] [Help] urllib.error.HTTPError: HTTP Error 400: Bad > Request > cm wrote: > >> Dear tutors, >> >> I have written below function to open the profanity check url and then >> to check for profanity in some text. When I go to the url >> http://www.wdylike.appspot.com/?q= and type in the same text, it works >> fine. >> >> I am using Microsoft OS X and Python 3.5.2 Interpreter with Pycharm >> Community Edition. >> >> --- >> import urllib.request >> >> def check_profanity(some_text): >> # check text for a curse word >> connection = >> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text) >> output = connection.read() >> print(output) >> connection.close() >> >> check_profanity(some_text="I gave it a good shot") >> --- >> >> Error message: >> Traceback (most recent call last): >> File >> "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py", >> line 29, in >> check_profanity(some_text="I gave it a good shot") >> File >> "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py", >> line 15, in check_profanity >> connection = >> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 163, in >> urlopen >> return opener.open(url, data, timeout) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 472, in >> open >> response = meth(req, response) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 582, >> in http_response >> 'http', request, response, code, msg, hdrs) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 510, in >> error >> return self._call_chain(*args) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 444, >> in _call_chain >> result = func(*args) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 590, >> in http_error_default >> raise HTTPError(req.full_url, code, msg, hdrs, fp) >> urllib.error.HTTPError: HTTP Error 400: Bad Request >> >> Process finished with exit code 1 >> >> --- >> However when I run the code it just says Bad Request. I tried to read >> into the traceback message but it refers not only to my file but the >> urllib function itself too and I can't understand. > > Spaces aren't allowed in the url: > c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice try") > [...] > urllib.error.HTTPError: HTTP Error 400: Bad Request > > Once you escape the ' ': > c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice+try";) c.read() > b'false' > > Have a look at the first example at > > https://docs.python.org/dev/library/urllib.request.html#urllib-examples > > for a more general solution. > > > > ___ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Pong code
Anyone know the pygame pong code and want to assist in a student learn where the mistakes in the code reside? Yes, reply to this mail. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pong code
On 13/02/18 13:41, terrapin-tur...@lycos.com wrote: > Anyone know the pygame pong code and want to assist in a student learn > where the mistakes in the code reside? > > Yes, reply to this mail. That's not how it works. You post a question and the code and any error messages and we (collectively) try to help you. It is a community tutor not one to one. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
I'm having a problem with my code on an interactive story. All the choices work until the end. When the code reaches the end, it will print different functions that aren't even set to be called in the code. I'm not sure what I've done wrong and can't ask anyone for help because they're learning the same rate as I am in my computer science class. If you would like, I can send you a link to my code on pythonroom.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 14/02/18 19:18, Nathantheweird1 wrote: > I'm having a problem with my code on an interactive story. All the choices > work until the end. When the code reaches the end, it will print different > functions that aren't even set to be called in the code. I'm not sure what > I've done wrong and can't ask anyone for help because they're learning the > same rate as I am in my computer science class. That shouldn't stop you. Everyone picks up different things, there's a pretty good chance that collectively you can solve the problem. > If you would like, I can > send you a link to my code on pythonroom.com. Well yes. We aren't psychic so, without seeing the code, we haven't a hope of guessing what you have done. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pong code
On 14/02/18 23:22, terrapin-tur...@lycos.com wrote: > > Alan, > > I know NOTHING of this program. > So how did you find it? What do you hope to do with it? BTW You sent this to me only,. you need to use Reply-All or Reply-List to include the tutor list. I've CCd the list in this response. > Here is what I have: > > import pygame > import sys > import random > pygame.init() > gameSurface=pygame.display.set_mode((450,450)) > pygame.display.set_caption("Pong Player") > pygame.mouse.set_visible(0) > > GREEN=(0,200,0) > BLUE=(0,0,128) > PURPLE=(102,0,102) > WHITE=(255,255,255) > > rect1x=20 > rect1y=100 > rect2x=400 > rect2y=100 > gameSurface.fill(WHITE) > pygame.draw.rect(gameSurface, GREEN,(rect1x, rect1y,30,150)) > pygame.draw.rect(gameSurface, GREEN,(rect2x, rect2y,30,150)) > ballx=random.randint(200,300) > bally=random.randint(100,150) > pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20) > pygame.display.update() > So this apparently draws two green rectangles and a ball at a random location. > FPS=20 > fpsClock=pygame.time.Clock() > This sets the frames per second timer to 20fps. > > pygame.key.set_repeat(1,1) > if event.type==KEYDOWN: > pygame.quit() > sys.exit() > The previous two lines should be indented. Indentation is critical in Python so you need to post in plain text not HTML or RTF. Without the indentation it gets difficult to tell what is going on. But in this case it basically exits the program when the KEYDOWN event is received. (Whatever KEYDOWN and event meanĀ in this context - I don't see them defined anywhere.) > if event.key==K_q: > ballx=ballx+1 > pygame.draw.circle(gameSurface, WHITE,(ballx, bally),20) > pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20) > If q is pressed it draws another 2 balls. I have no idea why, I never played pong... > > if event.key==K_LEFT: > ballx=ballx-1 > pygame.draw.circle(gameSurface, WHITE,(oldballx, bally),20) > pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20) > if ballx==70: > pygame.draw.rect(gameSurface, PURPLE,(rect1x, rect1y,30,150)) > if ballx==380: > pygame.draw.rect(gameSurface,PURPLE,(rect2x, rect2y,30,150)) > More of the same kind of thing. > pygame.display.update() fpsClock.tic(FPS) > > pygame.display.update() > > What it means > Its a game using PyGame. Have you read the PyGame tutorial? If not I suggest you start there and then try asking questions on the pyGame forum, because almost all the code is PyGame specific rather than generic Python. > Does this makes any sense to anyone? Sure, I'm sure a PyGame user would find it very straightforward. You probably just need to do some research/reading. But the big questions are: - what is it supposed to do? - What does it actually do? - do you get any error messages? If so what? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 02/14/2018 05:42 PM, Alan Gauld via Tutor wrote: > On 14/02/18 19:18, Nathantheweird1 wrote: >> I'm having a problem with my code on an interactive story. All the choices >> work until the end. When the code reaches the end, it will print different >> functions that aren't even set to be called in the code. I'm not sure what >> I've done wrong and can't ask anyone for help because they're learning the >> same rate as I am in my computer science class. > > That shouldn't stop you. > Everyone picks up different things, there's a pretty good chance > that collectively you can solve the problem. second that viewpoint... I know the classroom environment is different, but in most professional programming environments you will be working collaboratively with a team and unless you've been told not to do so in class, if it's not an exam, working with peers is a great way to learn skills you will use forever. In the Open Source Software world there's a famous quote "many eyeballs make all bugs shallow" (Eric Raymond, "The Cathedral and the Bazaar", a free essay that will be worth a read someday. It's often referred to as Linus' Law). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor