I’m trying to scraping web site with scrapy on pythonanywhere. I’m Scheduled the task to run specific time in daily. I have run_spider.py
and run_spider.sh
files for pythonanywhere. And pythonanywhere using run_spider.sh
to run. But I’m receiving 429 Unknown Status
when the scheduled time is come.
Additional TraceBack: 2024-08-05 16:01:56 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying <GET examplewebsite.com> (failed 1 times): 429 Unknown Status
And when I’m running manually like scrapy crawl fetch_stock
is running perfect no error or other things.
My settings.py file configuration is like this (this file contains which is the same location with scrapy.cfg
:
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
# Obey robots.txt rules
ROBOTSTXT_OBEY = False
# settings.py
# Configure maximum concurrent requests performed by Scrapy (default: 16)
# CONCURRENT_REQUESTS = 32
# CONCURRENT_REQUESTS = 32
# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 10 # Lower delay
CONCURRENT_REQUESTS_PER_DOMAIN = 3
CONCURRENT_REQUESTS = 3
CONCURRENT_REQUESTS_PER_IP = 3
# Disable cookies (enabled by default)
# COOKIES_ENABLED = False
# COOKIES_ENABLED = False
# Disable Telnet Console (enabled by default)
# TELNETCONSOLE_ENABLED = False
# TELNETCONSOLE_ENABLED = False
# Override the default request headers:
# DEFAULT_REQUEST_HEADERS = {
# DEFAULT_REQUEST_HEADERS = {
# "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
# "Accept-Language": "en",
# }
# }
# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
# SPIDER_MIDDLEWARES = {
# "snake.middlewares.SnakeSpiderMiddleware": 543,
# }
# }
# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# DOWNLOADER_MIDDLEWARES = {
# "snake.middlewares.SnakeDownloaderMiddleware": 543,
# }
DOWNLOADER_MIDDLEWARES = {
"fetch_stock.middlewares.FetchStockSpiderMiddleware": 543,
'scrapy.downloadermiddlewares.retry.RetryMiddleware': None,
'scrapy_user_agents.middlewares.RandomUserAgentMiddleware': 400,
}
# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
# EXTENSIONS = {
# "scrapy.extensions.telnet.TelnetConsole": None,
# }
# }
# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
# ITEM_PIPELINES = {
# ITEM_PIPELINES = {
# "snake.pipelines.SnakePipeline": 300,
# }
# }
# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
AUTOTHROTTLE_ENABLED = True
# The initial download delay
# AUTOTHROTTLE_START_DELAY = 5
AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 60
AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
# AUTOTHROTTLE_DEBUG = False
AUTOTHROTTLE_DEBUG = False
# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = "httpcache"
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = "scrapy.extensions.httpcache.FilesystemCacheStorage"
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = "httpcache"
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = "scrapy.extensions.httpcache.FilesystemCacheStorage"
# Set settings whose default value is deprecated to a future-proof value
REQUEST_FINGERPRINTER_IMPLEMENTATION = "2.7"
TWISTED_REACTOR = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
FEED_EXPORT_ENCODING = "utf-8"
My run_spider.py
file:
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
from fetch_stock.spiders.besled import StockSpider
process = CrawlerProcess(get_project_settings())
process.crawl(StockSpider)
process.start()
My run_spider.sh
file (this file contains which is the same location with scrapy.cfg
):
#!/bin/bash
python3.10 /home/zephyrus/shopify_fetch_stock/fetch_stock/run_spider.py