Thanks Kyle,

I don't have a system with access to curl and will download it for Windows 
later. Meanwhile I've put your code on my site.

Can you test it with curl for me? I tried testing for user agent starting 
with  Mozilla , from Firefox but it didn't work. 

http://www.australiansabroad.com

Many thanks!!!!!!

Kate

On Thursday, August 2, 2012 4:42:44 PM UTC-4, Kyle Finley wrote:
>
> Kate, sorry there were some errors
>
> Here's a working example:
>
> https://github.com/scotch/operation_curl_block/blob/master/appengine_config.py
>
> It should be "status" not "status_code", AntiCurlMiddleware not 
> AntiCurlMiddleware*y *and I used startswith *instead* of *is*
>
> You can test it here:
>
> *curl -v http://anticurl.scotch-media.appspot.com*
>
> will return:
>
> * About to connect() to anticurl.scotch-media.appspot.com port 80 (#0)
> *   Trying 173.194.77.141... connected
> * Connected to anticurl.scotch-media.appspot.com (173.194.77.141) port 80 
> (#0)
> > GET / HTTP/1.1
> > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 
> OpenSSL/0.9.8r zlib/1.2.5
> > Host: anticurl.scotch-media.appspot.com
> > Accept: */*
> > 
> < HTTP/1.1 *423* Locked
> < Content-Type: text/html; charset=UTF-8
> < Vary: Accept-Encoding
> < Date: Thu, 02 Aug 2012 20:40:13 GMT
> < Server: Google Frontend
> < Cache-Control: private
> < Transfer-Encoding: chunked
> < 
> * Connection #0 to host anticurl.scotch-media.appspot.com left intact
> * Closing connection #0
> *Too many requests!*
>
> I hope that helps
>
> - Kyle
>
> On Thursday, August 2, 2012 2:47:57 PM UTC-5, Kate wrote:
>>
>> I am looking for 'win' in user agent as that IS the USER Agent I am using 
>> to test. It should evaluate to true  and give a 423 error.
>>
>> I do not want to test it using curl. I am trying to see if I can return a 
>> 423 error. It is a TEST!
>>
>> I am running it locally to see if it will block.
>>
>> It doesn't.
>>
>> 'Win' is in my user agent - as I am testing.
>>
>>
>>
>>
>> On Thursday, August 2, 2012 3:43:44 PM UTC-4, hyperflame wrote:
>>>
>>> You're trying to find curl requests by looking for a "win" string? 
>>> IIRC, curl uses "curl" as its default user-agent, you have to look for 
>>> that. Also, it's a bad idea to look for "Win", as legitimate requests 
>>> (users using WINdows) will be blocked. 
>>>
>>> Also, it should be noted (and I believe a number of people have 
>>> already mentioned) that curl allows a person to change their user- 
>>> agent; just looking for a "curl" user-agent may not stop the problem. 
>>>
>>> On Aug 2, 1:55 pm, Kate <mss.ka...@gmail.com> wrote: 
>>> > Well I tried this by testing user agent but it passes the test and the 
>>> page 
>>> > loads correctly, which it shouldn't in this example. 
>>> > Am I meant to pass 'app' as such? I am not sure of this parameter. 
>>> > 
>>> > Here is my code 
>>> > from webob import Response 
>>> > 
>>> > class AntiCurlMiddleware(object): 
>>> >     def __init__(self, app): 
>>> >         self.app = app 
>>> > 
>>> >     def __call__(self, environ, start_response): 
>>> >         ua = os.environ.get('HTTP_USER_AGENT', "unknown") 
>>> > sindex = string.find(ua,'Win',0) 
>>> > if sindex > 0: 
>>> >       resp = Response('Too many requests!') 
>>> >       resp.status_code = 423 
>>> >       return resp(environ, start_response) 
>>> >         return self.app(environ, start_response) 
>>> > 
>>> > def webapp_add_wsgi_middleware(app): 
>>> >     return AntiCurlMiddlewarey(app) 
>>> > 
>>> > 
>>> > 
>>> > 
>>> > 
>>> > 
>>> > 
>>> > On Wednesday, August 1, 2012 4:43:58 PM UTC-4, Kate wrote: 
>>> > 
>>> > > I am getting tens of thousands of curl requests - many thousands 
>>> time 
>>> > > browser requests and I want to block them. I'm using python. They 
>>> coming 
>>> > > from many different IPs most in Europe.  If I can't stop them I will 
>>> have 
>>> > > to close my site or go to a new provider. 
>>> > 
>>> > > Thank in advance, 
>>> > 
>>> > > Kate 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/OQh8YTtF26cJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to