标签: http-status-code-404

捕获Mechanize 404 => Net :: HTTPNotFound

我写了一个简单的函数来处理url的获取:

def tender_page_get url, agent
  sleep(rand(6)+2)
  begin
    return agent.get(url).parser
  rescue Errno::ETIMEDOUT, Timeout::Error, Net::HTTPNotFound
    EYE.debug "--winter sleep #{url}"
    puts "-x-#{url}"
    sleep(300)
    tender_page_get url, agent
  rescue => e
    puts "-x-#{url}"
    EYE.debug "--unknown exception"
    EYE.debug "#{url} #{e.inspect}"
  end
end
Run Code Online (Sandbox Code Playgroud)

问题是,即使我Net::HTTPNotFound在第一个救援区中捕获,我仍然在我的日志记录中看到:

--unknown exception
{url} 404 => Net::HTTPNotFound
Run Code Online (Sandbox Code Playgroud)

这意味着第二个救援区抓住了这个例外.可能是什么原因?

ruby http-status-code-404 mechanize-ruby

12
推荐指数
1
解决办法
6484
查看次数

在Rails 3中捕获自定义404的未知操作

我想在Rails 3中捕获未知的操作错误,该错误显示开发时的"未知操作"错误以及生产中的404.html.我尝试将此rescue_from处理程序放在我的ApplicationController上(以及实际的控制器,以防万一),但我仍然看到了丑陋的错误.

我在404上有自定义的东西,它不能是普通的.html文件.

我的路线:

match '/user/:id/:action', controller: 'users'
Run Code Online (Sandbox Code Playgroud)

我正在访问的URL: /user/elado/xxx

该rescue_from代码:

rescue_from AbstractController::ActionNotFound, :with => :action_not_found

def action_not_found
  render text: "action_not_found"
end
Run Code Online (Sandbox Code Playgroud)

浏览器中的错误:

Unknown action

The action 'xxx' could not be found for UsersController
Run Code Online (Sandbox Code Playgroud)

在控制台中:

Started GET "/user/elado/xxx" for 127.0.0.1 at 2011-09-07 19:16:27 -0700

AbstractController::ActionNotFound (The action 'xxx' could not be found for UsersController):
Run Code Online (Sandbox Code Playgroud)

也试过rescue_from ActionController::UnknownAction.

有什么建议?谢谢!

ruby-on-rails http-status-code-404 ruby-on-rails-3

12
推荐指数
2
解决办法
1万
查看次数

Laravel PHP框架的新功能."/"以外的路由不起作用

我是Lavarel框架的初学者.我知道MVC结构,因为我之前在ASP.net中使用过它,但使用Laravel对我来说很困惑.

我photozoom使用以下命令在目录中安装了Laravel :

composer create-project laravel/laravel photozoom --prefer-dist
Run Code Online (Sandbox Code Playgroud)

这是我的app/routes.php:

<?php

Route::get('/', function()
{
    return View::make('hello');
});

Route::get('users', function()
{
    return 'users route is working!';
});
Run Code Online (Sandbox Code Playgroud)

当我跑http://localhost/photozoom/public/users,我得到404 Not Found错误.

但是当我尝试时http://localhost/photozoom/public/,/调用路由并调用相应的视图.

我甚至试图为users路线创建一个视图.使用Laravel文档.我创建了两个文件:

layout.blade.php :

<html>
    <head>
        <title>Laravel Quickstart</title>
    </head>
    <body>
        <h1>Laravel Quickstart</h1>

        @yield('content')
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

users.blade.php :

@extends('layout')

@section('content')
    Users!!!
@stop
Run Code Online (Sandbox Code Playgroud)

但是,当我打电话给http://localhost/photozoom/public/users我的时候404 Not Found error.

这是我的public/.htaccess档案:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On …
Run Code Online (Sandbox Code Playgroud)

php http-status-code-404 laravel

12
推荐指数
2
解决办法
1万
查看次数

未找到nginx位置404

这是我的nginx配置文件.

在default.conf中,第一个位置用于访问/ usr/share/nginx/html目录,当我访问http://47.91.152.99时可以.但是当我为目录/ usr/share/nginx/public目录添加一个新位置时,当我访问http://47.91.152.99/test时,nginx会返回404页面.

那么,怎么回事?我是否误用了nginx的指令?

/etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}


/etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location …
Run Code Online (Sandbox Code Playgroud)

location nginx http-status-code-404

12
推荐指数
2
解决办法
4万
查看次数

Flask 的内置服务器总是 404 设置 SERVER_NAME

这是一个最小的例子:

from flask import Flask

app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SERVER_NAME'] = 'myapp.dev:5000'


@app.route('/')
def hello_world():
    return 'Hello World!'

@app.errorhandler(404)
def not_found(error):
    print(str(error))
    return '404', 404


if __name__ == '__main__':
    app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)

如果我设置了SERVER_NAME,Flask 会以 404 错误响应每个URL,当我注释掉该行时,它会再次正常运行。

/Users/sunqingyao/Envs/flask/bin/python3.6 /Users/sunqingyao/Projects/play-ground/python-playground/foo/foo.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 422-505-438
127.0.0.1 - - [30/Oct/2017 07:19:55] "GET / HTTP/1.1" 404 -
404 Not Found: The requested URL was not …
Run Code Online (Sandbox Code Playgroud)

python werkzeug pycharm flask http-status-code-404

12
推荐指数
2
解决办法
8602
查看次数

Laravel:如何根据路由响应自定义404错误

我正在使用Laravel4框架,我遇到了这个问题.

我想根据请求的URL显示自定义404错误.

例如:

Route::get('site/{something}', function($something){
    return View::make('site/error/404');
});
Run Code Online (Sandbox Code Playgroud)

和

Route::get('admin/{something}', function($something){
    return View::make('admin/error/404');
});
Run Code Online (Sandbox Code Playgroud)

价值'$something'并不重要.

所示示例仅适用于一个段,即'site/foo'或'admin/foo'.如果有人请求'site/foo/bar'或'admin/foo/bar'laravel将抛出默认404错误.

App::missing(function($exception){
    return '404: Page Not Found';
});
Run Code Online (Sandbox Code Playgroud)

我试图在Laravel4文档中找到一些东西,但没有什么是适合我的.请帮忙 :)

谢谢!

http-status-code-404 laravel laravel-4 laravel-routing

11
推荐指数
1
解决办法
9277
查看次数

Flask路由在URL中给出404浮点数

我在Flask应用程序的server.py中有以下路由定义:

@app.route('/nearby/<float:lat>/<float:long>')
def nearby(lat, long):
    for truck in db.trucks.find({'loc': {'$near': [lat, long]}}).limit(5):
        if truck.has_key('loc'):
            del truck['loc']
    return json.dumps(trucks)
Run Code Online (Sandbox Code Playgroud)

但是当我去的时候http://localhost:5000/nearby/37.7909470419234/-122.398633589404,我得到了404.

其他路线工作正常,所以这是一个问题.我在这做错了什么?

python routes werkzeug flask http-status-code-404

11
推荐指数
3
解决办法
3419
查看次数

Youtube Player API引发404

这已经困扰了我一段时间了,我正在使用这个通用脚本来创建一个播放器

var player = new YT.Player(videoArray[0], { videoId : videoArray[0], events : { 'onStateChange' : onPlayerStateChange } });

我有一个简单的console.log设置回调函数问题是当我改变控制台抛出的玩家的状态

https://www.youtube.com/get_video?noflv=1&video_id=ghUA ....来自文件html5player-en_US-vfloyxzv5.js的GET 404:我认为这是由YouTube Iframe API加载的.

任何ideeas或posibile解决方案都会受到极大的影响.

html javascript youtube api http-status-code-404

11
推荐指数
1
解决办法
2277
查看次数

使用Webpack将Angular 2 App部署到Tomcat - 404错误

我想构建我的Angular 2前端并将其部署到Tomcat应用程序服务器.为了开始,我完全按照以下介绍的步骤进行操作:https://angular.io/docs/ts/latest/guide/webpack.html.

所以我有以下项目结构(所有文件都与上面提到的引言完全相同):

angular2-webpack
--- config
------- helpers.js
------- karma.conf.js
------- karma-test-shim.js
------- webpack.common.js
------- webpack.dev.js
------- webpack.prod.js
------- webpack.test.js
--- dist
--- node_modules
- --public
------- css
-------------- styles.css
------- images
-------------- angular.png
--- src
------- app
-------------- app.component.css
-------------- app. component.html
-------------- app.component.spec.ts
-------------- app.component.ts
------- ------- app.module.ts
------- index.html
------- main.ts
------- polyfills.ts
------- vendor .ts
---
typings --- karma.conf.js
--- package.json
--- tsconfig.json
--- typings.json
--- webpack.config.js

npm分别webpack-dev-server --inline --progress …

tomcat http-status-code-404 webpack angular

11
推荐指数
2
解决办法
2万
查看次数

REST 404 与 400。使用哪一个?

如果我有如下所示的 REST 资源:

获取http://www.example.com/customers/ {customerId}/orders

如果提供的 customerId 不存在,我的服务器应该返回 404(未找到)还是 400(错误请求)?

rest http-status-codes http-status-code-404

11
推荐指数
2
解决办法
1万
查看次数